« IABC/PRSA Spring Conference | Main | Conversing With Your Customers »

Opening Finder Folder in iTerm

I saw a little script in Macworld that allows you to right click on a folder in Finder and have it open in Terminal. I often find it handy to use the command line and the Finder simultaneously, so this seemed like a handy thing to do. Note that you can always open the current directory in Finder by typing open . at the command line.

The problem is that the Macworld script is set up for Terminal and I use iTerm because I like the tabs. I found this script but it required the installation of some other things which I didn’t want to do. So, I combined the ideas from both scripts to create one that does the job:

tell application "Finder"
    set myWin to window 1
    set theWin to (quoted form of POSIX path of  (target of myWin as alias))
	tell application "iTerm"
    	make new terminal
    	tell the first terminal
       		activate current session
       		launch session "Default Session"
       		tell the last session
          		write text "cd " & theWin
       		end tell
    	end tell
    end tell
end tell
tell application "Finder"
    activate
end tell
tell application "iTerm"
    activate
end tell

To use this, open Automator and select Finder in the Library column and then drag the Get Selected Finder Items action followed by the Run Applescript action. Replace all the code in the Run Applescript action with the above code. Save it as a plug-in for Finder with a meaningful name (like “Open in iTerm”). You’re done. Now, right-click on a folder in Finder and select the script from the menu. You’ll get that directory in a new tab in iTerm.

Posted by windley on May 10, 2006 8:44 AM

See related posts:

1 Comments

Comment from Mike at May 10, 2006 11:01 AM

A straight copy and paste didn't work for me. I noticed however that if I took out the line breaks on the following line that it worked fine:

set theWin to (quoted form of POSIX path of (target of myWin as alias))


It looks like there is a word wrap problem when you copy and paste. Hope that helps!