177

I was wondering if there was any was I could right click inside any instance of a "Finder" window such that I have an option that says "Open Terminal Here". It would be really helpful.

0

17 Answers 17

190

As of Mac OS X Lion 10.7, Terminal provides Services for opening a new terminal window or tab at the selected folder in Finder. They also work with absolute pathnames selected in text (in any application). You can enable these services with System Preferences > Keyboard > Keyboard Shortcuts > Services. Look for "New Terminal at Folder" and "New Terminal Tab at Folder". You can also assign them shortcut keys.

In addition, you can now drag folders (and pathnames) onto the Terminal application icon to open a new terminal window, or onto a tab bar in a terminal window to create a new tab in that window. If you drag onto a tab (rather than into the terminal view) it will execute a complete cd command to switch to that directory without any additional typing.

As of OS X Mountain Lion 10.8, Command-Dragging into a terminal will also execute a complete cd command.

Note: 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.

7
  • T'was already enabled on mine, but with key set to 'none'. Is there a recommended shortcut? (side note: really wish MacOS had something set by default, so it wouldn't be left to everyone having to do it manually themselves and hence different shortcuts for each user)
    – stevec
    Jul 18, 2020 at 7:03
  • 4
    @stevec or at least a list of available shortcuts. Btw: this is only working when you click on a folder, not when you don't have a folder or a file focused. In this case it should just open on the desktop or in root and be a global shortcut in general. Super annoying.
    – BlkPengu
    Jul 22, 2020 at 12:56
  • 3
    Doesn't work on Bug Sur. I couldn't find Services on the right-click menu!
    – Dr.jacky
    Nov 18, 2020 at 14:42
  • 1
    @ChrisPage Thanks! It works. The issue was, there were lots of items in right-click so, I couldn't see that specific one.
    – Dr.jacky
    Mar 20, 2021 at 15:44
  • 2
    This only works when your are outside of a given folder, and you are selecting it. It does not work if you are already in it. Classic Apple.
    – Franc
    May 30, 2022 at 17:30
24

The solution to your troubles is called Go2Shell and it does exactly what you're describing. You can find it on the App Store and best of all... it's totally free.

Go2Shell

4
  • 2
    Not work in Catalina!
    – Dr.jacky
    Jun 30, 2020 at 15:10
  • 1
    The version on the App Store doesn't download for Catalina, but the version directly from the developers can be downloaded and appears to work: zipzapmac.com/Go2Shell
    – ThomasW
    Aug 17, 2020 at 1:22
  • 1
    Didn't get it running on Catalina either. Even though I pressed "add to finder" button I do not see any new button in Finder.
    – guglhupf
    Oct 20, 2020 at 8:48
  • Direct link: zipzapmac.com/DMGs/Go2Shell.dmg
    – user674669
    Apr 14, 2021 at 9:09
23

cdto seems like it is just what you need. It is a mini-application, designed to be put in the Finder's toolbar, when you run it it will open a terminal window and cd to the current directory in Finder.

4
  • Works well on Catalina
    – guglhupf
    Oct 20, 2020 at 8:54
  • Works well on Big Sur.
    – neoneye
    Dec 22, 2020 at 19:41
  • Newer versions don't support opening iTerm2 :\
    – Carl Walsh
    Dec 15, 2021 at 21:48
  • Works well in Ventura for M1/2 chips Apr 19 at 22:46
18

For those using iTerm, the AppleScript syntax has change in iTerm version 3. Here's the full procedure to follow to create a shortcut in the Finder.

  1. Launch Automator.

  2. Select "Application" :

illustration of instructions

  1. Choose "run Applescript" :

enter image description here

  1. Paste the code below:

    -- get the current directory in Finder
    on run {input, parameters}
        tell application "Finder"
            set _cwd to quoted form of (POSIX path of (folder of the front window as alias))
        end tell
        CD_to(_cwd)
    end run
    
    -- change directory in iTerm (version >= 3)
    on CD_to(_cwd)
        tell application "iTerm"
            activate
    
            try
                set _window to first window
            on error
                set _window to (create window with profile "Default")
            end try
    
            tell _window
                tell current session
                    write text "cd " & _cwd & ";clear;"
                end tell
            end tell
        end tell
    end CD_to
    

enter image description here

  1. Click "File" -> "Export" to export as an .app, save it in /Applications.

  2. Move the application to the Finder icons bar while holding :

enter image description here

Done !

You can change the icon in the Finder by following the instructions here (change the icon of the application you created with Automator).

2
  • 2
    Any update for big Sur ?
    – tong
    Mar 7, 2021 at 13:15
  • For iTerm, the existing answer about Services also applies: Finder > Services > New iTerm2 Window Here is available by default.
    – Carl Walsh
    Oct 20, 2021 at 18:23
15

A different approach: DTerm, which gives you a floating command prompt at the top of the window. This works in many apps, not just Finder.

0
14

If you have the "Path Bar" shown (View > Show Path Bar). You can Right Click on any element to get a Open In Terminal option

enter image description here

1
  • 6
    This is perhaps the best answer, no System property change, no additional tools. Sep 10, 2022 at 9:14
11

I mostly use this function:

cf() {
  cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
}

You could also assign a shortcut to a script like the ones below.

Reuse an existing tab or create a new window (Terminal):

tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
    if (exists window 1) and not busy of window 1 then
        do script "cd " & quoted form of p in window 1
    else
        do script "cd " & quoted form of p
    end if
    activate
end tell

Reuse an existing tab or create a new tab (Terminal):

tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
    if not (exists window 1) then reopen
    activate
    if busy of window 1 then
        tell application "System Events" to keystroke "t" using command down
    end if
    do script "cd " & quoted form of p in window 1
end tell

Always create a new tab (iTerm 2):

tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "iTerm"
    if exists current terminal then
        current terminal
    else
        make new terminal
    end if
    tell (launch session "Default") of result to write text "cd " & quoted form of p
    activate
end tell

The first two scripts have a few advantages compared to the services added in 10.7:

  • As of 10.9, there is a bug where services that receive folders as input are never listed in the services menu in column view. If you assign the New Terminal Tab at Folder service a keyboard shortcut, it doesn't work in column view.
  • They use the folder on the title bar instead of requiring you to select a folder first.
  • They reuse the frontmost tab if it is not busy, e.g. running a command, displaying a man page, or running emacs.

If you use 10.7 or 10.8, change tell application "Finder" to set p to POSIX path of (insertion location as alias) to:

tell application "Finder"
    if exists Finder window 1 then
        set p to POSIX path of (target of Finder window 1 as alias)
    else
        set p to POSIX path of (path to desktop)
    end if
end tell

There is a bug in 10.7 and 10.8 (but not in 10.9 or 10.6) where Finder ignores windows created after the last time focus was moved to another application and back when getting the insertion location property.

1
6

Try this: https://github.com/nmadhok/OpenInTerminal

It works with the Finder's sidebar items, multiple folder/file selections and anything you could think of. Really easy to use!

1
  • It works well with high sierra!
    – Ivelin
    Oct 23, 2017 at 16:06
5

You can drag any file or folder from the finder onto a Terminal window to insert a string of said file or folder's absolute path.

This will work on any standard install (at least back until 10.4 Tiger [¿maybe earlier?]) without needing additional software our twiddling of preferences, either of which may later freak out your non-techy friend if it happens to be his/her Mac that you’re working on. This trick also works for any process that is running in the Terminal, e.g. emacs or vi (assuming you’ve got vi in the appropriate mode, or however it is that you people who use vi do).

3

You can do this with the service feature.

The following site contains an example of such a service: http://blog.leenarts.net/2009/09/03/open-service-here/

3

Service Station, on the Mac App Store, allows you to fully customize your right-click menu in Finder.

One of the most popular actions is to open Terminal by right-clicking in the Finder:

Open Terminal from Finder using Service Station

I'm the developer and would love if you gave it a try.

The app is fully sandboxed and uses the modern Finder Sync Extension API. I like using it more than the Services menu, as detailed in other answers, as you don't have to dig through the submenu.

3

OpenInTerminal

You could try OpenInTerminal: https://github.com/Ji4n1ng/OpenInTerminal

It has a really nice icon and is implemented as Finder Extension. There are also two versions ('regular' and 'lite).

OpenInTerminal can also be installed using homebrew:

brew install --cask openinterminal
2

ShellHere

http://etresoft.org/shellhere.html — Etresoft and John Daniel

… right click inside any instance of a "Finder" window …

I don't know whether it can be reached through a contextual menu, but I keep ShellHere in the toolbar of Finder.

0
2

OnMyCommand

http://free.abracode.com/cmworkshop/on_my_command.html — version 2.3 (2011-01-16)

Screenshot etc. at http://www.wuala.com/grahamperrin/public/2011/07/31/d/?mode=gallery

Installed and used by me on Snow Leopard before upgrading to Lion. Too soon for me to say whether version 2.3 is compatible with Lion.

2

You can the app I developed FinderGo, which is open source and easy to use

0
2

I use this for years http://openterminal.quentin.paris/
Just right click on anywhere Finder, choose Open Terminal

1
0

Try the app Open Terminal

This application allows you to open a Terminal window with the path of the current Finder window.

Open Terminal app icon

0

You must log in to answer this question.