Skip to content

Open Terminal in selected Finder folder

Today's tip is just a re-implementation of a really old Mac OS X Hints AppleScript that lets you open a Terminal window with the working directory set to (i.e. cd'd into) the selected Finder folder.

This makes it really easy to jump into Terminal to do something from Finder, without having to do any mousing and minimal typing. What's new is that I've used Keyboard Maestro to turn the AppleScript into a macro that runs only in Finder, where it's available via hot key or menu bar trigger.

Here's the complete macro; download it now to look at and/or use as you wish. [Note: If you use iTerm2 instead of Terminal, you'll want to download this version instead. My good friend James, who runs Out of Control, did so. He tells me it works great.]

The name of the macro may look a bit odd—the 03) controls the sort order in the Keyboard Maestro menu bar item, and does not display when the menu is activated:

Keyboard Maestro also helpfully displays the assigned keyboard shortcut in the menu bar item, in case I've forgotten it.

I like this macro because it's incredibly easy to use; it doesn't matter if you have a folder or file selected. Just invoke the macro, and Terminal opens to either the selected folder, or to the folder containing the selected file:

If you'd just like the AppleScript bit to use elsewhere, here it is:

That's really all there is to it—just a simple little macro that makes it much easier to jump into Terminal when I realize I need it set to the folder I'm currently browsing in Finder.

4 thoughts on “Open Terminal in selected Finder folder”

  1. How about: open Terminal window, type "cd " (without the quotes), then go up one level in the Finder window and drag the directory you want onto the Terminal window. It enters the appropriate text. Type Enter to execute the cd (change directory) command and you're done.

  2. That works, with two problems. First, it requires grabbing the mouse and navigating, potentially a long distance on a big screen, depending on where Terminal is. I used the mouse for the video, but in practice, I just press my keyboard shortcut and I'm there instantly.

    The bigger issue, though, is that you must select a folder; if you try to 'cd' to a dragged file, it won't work.

    regards;
    -rob.

  3. There is a "New Terminal at Folder" service, but it doesn't work unless a folder is selected, i.e. your dragged file solution.

Comments are closed.