Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 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.

share|improve this answer
    
Thanks, joelseph. Yeah, I currently use the drag folder into Terminal trick, but would love to just be able to right-click on a Folder and have it open Terminal, then having to open Terminal, type cd , and then drag the folder. I'll give the above a go and let you know how I get on! –  Martin Bean Mar 3 '12 at 17:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.