A subject that has been visited plenty of times is having an “Open Terminal Here” ability from the Finder. For developers, it’s a easy way to look at files or folders and then jump quickly to a shell for the folder and execute shell commands (like mv or cp). Or to execute a build using make or ant.

I decided to make a version of that would work off the “Services” context menu. If you control-click a file and select Services | Open Terminal Here you’ll be taken to the folder containing that file. A control-click on a folder will take you to the folder you selected.

To use it, just unzip this file and put it in your ~/Library/Services folder.

Open Terminal Here.zip

The code itself is pretty straightforward:

(* 
   Workflow - Open Terminal Here 
   By David Orriss Jr - November 2010
   Another "Open Terminal Here" option.  This time as a service workflow in Automator

   For Snow Leopard
*)
on run {input, parameters}
	
	set the_path to (the POSIX path of input)
	
	set AppleScript's text item delimiters to "/"
	
	
	if the_path does not end with "/" then
		set parentPath to (items 1 thru -2 of text items of the_path) as string
		set the_path to parentPath
	end if
	
	set cmd to "cd " & quoted form of the_path & " && echo $'\ec'"
	
	tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
	
	tell application "Terminal"
		activate
		if terminalIsRunning is true then
			do script with command cmd
		else
			do script with command cmd in window 1
		end if
	end tell
end run