Open In Terminal (10.5 only)

Decided to write this up since i haven’t found a good one since Open In termainl wouldn’t run on intel, and was inspired by This Post on the TextMate Blog.


on run
	tell application "Finder"
		if selection is {} then
			set finderSelection to folder of the front window as string
		else
			set finderSelection to selection --as alias list
		end if
	end tell
	
	tm(finderSelection)
end run

-- script was drag-and-dropped onto
on open (theList)
	tm(theList)
end open

-- open in Terminal
on tm(listOfAliases)
	set theItem to item -1 of listOfAliases
	tell application "Finder"
		if item -1 of (URL of theItem as string) = "/" then
			set theDir to quoted form of POSIX path of (theItem as alias)
		else
			set theDir to quoted form of POSIX path of ((container of theItem) as alias)
		end if
	end tell
	set already_open to application id "com.apple.terminal" is running
	tell application "Terminal"
		if already_open then
			do script "cd " & theDir
		else
			do script "cd " & theDir in window 1
		end if
		activate
	end tell
end tm