I often find myself wanting to open a terminal in the directory I’m staring at in the Finder.
I usually drag folders (or their proxy icons) onto the Terminal, or I type cd and drag into an existing terminal window1.
But today it occurred to me that you can probably add a button to the Finder’s toolbar to do this in one click, and it occurred to me that ChatGPT could probably do it for me.
Yes, and yes.
The solution turned out to be surprisingly simple. So simple that I’m quite sure there are a thousand blog posts already detailing this solution.
This is mine. Sort of.
First, create a new Automator Application containing a single “Run AppleScript” action:
tell application "Finder"
set targetFolder to POSIX path of ((target of front window) as alias)
end tell
do shell script "open -a Terminal " & quoted form of targetFolder
Save it somewhere permanent. I put it in ~/Applications/Open Terminal Here.app.
Then ⌘-drag the application into the Finder toolbar.
Now every Finder window has a button that opens Terminal directly in the current directory. Hooray!
One small wrinkle: my first attempt used Terminal’s do script command to execute a cd command. That mostly worked, but occasionally terminal startup output would appear before the command executed, swallowing the cd and dumping me in the home directory.
Using open -a Terminal <folder> seems to bypass this issue. Terminal starts with the correct working directory from the beginning, so there is no command to race against shell startup messages.
For bonus points, you can make the Automator app look like Terminal:
- Open Terminal.app’s Get Info window (⌘I).
- Click the icon in the upper-left corner and copy it (⌘C).
- Open the Get Info window for your new Automator app.
- Click its icon and paste (⌘V).
Now the toolbar button is visually indistinguishable from a native Terminal command, and I can get a Terminal window in one click rather than several.
-
It turns out there’s also a Service for this, if you want to right-click and hunt for it in a sub-menu. ↩︎