Open terminal here in Mac OS finder

623,987

Solution 1

As of Mac OS X Lion 10.7, Terminal includes exactly this functionality as a Service. As with most Services, these are disabled by default, so you'll need to enable this to make it appear in the Services menu.

System Preferences > Keyboard > Shortcuts > Services

Enable New Terminal at Folder. There's also New Terminal Tab at Folder, which will create a tab in the frontmost Terminal window (if any, else it will create a new window). These Services work in all applications, not just Finder, and they operate on folders as well as absolute pathnames selected in text.

You can even assign command keys to them.

Services appear in the Services submenu of each application menu, and within the contextual menu (Control-Click or Right-Click on a folder or pathname).

The New Terminal at Folder service will become active when you select a folder in Finder. You cannot simply have the folder open and run the service "in place". Go back to the parent folder, select the relevant folder, then activate the service via the Services menu or context menu.

In addition, Lion Terminal will open a new terminal window if you drag a folder (or pathname) onto the Terminal application icon, and you can also drag to the tab bar of an existing window to create a new tab.

Finally, if you drag a folder or pathname onto a tab (in the tab bar) and the foreground process is the shell, it will automatically execute a "cd" command. (Dragging into the terminal view within the tab merely inserts the pathname on its own, as in older versions of Terminal.)

You can also do this from the command line or a shell script:

open -a Terminal /path/to/folder

This is the command-line equivalent of dragging a folder/pathname onto the Terminal application icon.

On a related note, Lion Terminal also has new Services for looking up man pages: Open man page in Terminal displays the selected man page topic in a new terminal window, and Search man Pages in Terminal performs "apropos" on the selected text. The former also understands man page references ("open(2)"), man page command line arguments ("2 open") and man page URLs ("x-man-page://2/open").

Solution 2

This:

https://github.com/jbtule/cdto#cd-to

It's a small app that you drag into the Finder toolbar, the icon fits in very nicely. It works with Terminal, xterm (under X11), iterm.

Solution 3

An application that I've found indispensible as an alternative is DTerm, which actually opens a mini terminal right in your application. Plus it works with just about everything out there - Finder, XCode, PhotoShop, etc.

Solution 4

Clarification (thanks @vgm64): if you're already in Terminal, this lets you quickly change to the topmost Finder window without leaving Terminal. This way, you can avoid using the mouse.

I've added the following to my .bash_profile so I can type cdff in Terminal at any time.

function ff { osascript -e 'tell application "Finder"'\
 -e "if (${1-1} <= (count Finder windows)) then"\
 -e "get POSIX path of (target of window ${1-1} as alias)"\
 -e 'else' -e 'get POSIX path of (desktop as alias)'\
 -e 'end if' -e 'end tell'; };\

function cdff { cd "`ff $@`"; };

This is from this macosxhints.com Terminal hint.

Solution 5

Check out Open Terminal Here. It may be the most similar to "Open Command Window Here." I used >cdto and this is very similar but this seems to be a little better at dealing with Spaces... but not perfect.

What it has that is very nice is the ability to "detect key-down events at the start of the application and used them to modify the behavior of the script" allowing the script to open a new tab in the front most terminal window when invoked by holding down ⌘ key. Neat trick.

Also note PCheese's answer; it is probably more useful for heavy terminal users!

Share:
623,987
Abdullah Jibaly
Author by

Abdullah Jibaly

We're hiring top engineering talent at Oculus, contact me if you're interested.

Updated on July 16, 2022

Comments

  • Abdullah Jibaly
    Abdullah Jibaly almost 2 years

    Is there something similar to the "Open Command Window Here" Windows Powertoy for Mac OS? I've found a couple plugins through a google search but wanted to see what works best for developers out there.

  • Rob Kennedy
    Rob Kennedy almost 14 years
    Why would you want to close a Terminal window? Won't that destroy whatever work you were doing in it?
  • Sebastian Graf
    Sebastian Graf over 9 years
    For some reason, the shortcut works only sporadically for me, but the drag-on-terminal works!
  • jolvi
    jolvi over 9 years
    "open . " opens a new Finder window in the current directory
  • Olcay Ertaş
    Olcay Ertaş over 9 years
    Doesn't work on Yosemite.
  • Chris Page
    Chris Page over 9 years
    @OlcayErtaş What doesn’t work? Everything in my answer works on Yosemite 10.10.x.
  • Olcay Ertaş
    Olcay Ertaş over 9 years
    Do I have to restart Finer? I don't why but I have enabled New Terminal at Folder service but it didn't work.
  • Jonathan E. Landrum
    Jonathan E. Landrum over 9 years
    @OlcayErtaş you have to right click on a folder icon to get the menu item; don't navigate to the folder itself, but to its parent.
  • Jonathan E. Landrum
    Jonathan E. Landrum over 9 years
    @jolvi that is the opposite of what this answer provides. The point isn't to open a finder window at pwd, but to cd to the directory in which finder is open.
  • jolvi
    jolvi over 9 years
    ah, sorry, of course you are right.
  • wisbucky
    wisbucky about 9 years
    "Go back to the parent folder, select the relevant folder, then activate the service via the Services menu or context menu." Actually, you don't have navigate to the parent if you have the Path Bar (breadcrumbs) viewable. You can right click on the current folder (or any ancestor folder) and get the New Terminal at Folder menu item.
  • Can Poyrazoğlu
    Can Poyrazoğlu almost 9 years
    I can use it through right click/services but I can't use it through keyboard shortcuts.
  • B. Nadolson
    B. Nadolson almost 9 years
    This is awesome! Note you have to Command+Drag (not just drag as stated in above post) it to the Finder Toolbar. And then you have an icon shortcut that when clicked will terminal from any folder.
  • dumbledad
    dumbledad almost 9 years
    I was actually hoping to find out what I had to put in a command file to open a terminal with a specific working directory and so open -a Terminal /path/to/folder was exactly what I needed. Thanks.