MacOS – How to make a custom context menu item in Finder

macos

I do a lot of command line work, which involves a lot of folder navigation with cd.

To make my life easier, I'd love to be able to right-click on a folder in Finder and have a context menu item I could click that simply opens Terminal and cds to that directory.

How would I go about this in OS X (Snow Leopard)? I'm a website developer, so familiar with programming languages and computer literate, so feel free to get technical with me.

Best Answer

If you want the cd command in a new window or tab, you can simply turn on the built-in services, "New Terminal at Folder" and "New Terminal Tab at Folder", by going to System Preferences > Keyboard > Keyboard Shortcuts > Services > Files and Folders.

If you want the cd command in the active window or tab, you can make a simple Automator Service.

  1. In a new Automator Service, change "Service receives selected" to folders.
  2. Add a "Run AppleScript" action.
  3. Replace (* Your script goes here *) with the following:

    tell application "Terminal"
        reopen
        activate
        set cmd to "cd " & quoted form of posix path of input
        try
            if busy of selected tab of window 1 then error
            do script with command cmd in window 1
        on error
            do script with command cmd
        end try
    end tell
    
  4. Save the service with whatever name you want your menu item to have, then it's ready to go.

An alternative to using a contextual menu is to just type cd (with a trailing space) then drag the folder to the Terminal window.