A script to automatically open a Terminal window to its directory

Jun 28, '11 07:30:00AM

Contributed by: nathanator11

How many times have you been to a folder in Finder and needed a Terminal window open to that folder? For me, the answer was many. So, I wrote little AppleScript to take care of it automatically.

This script works by opening a Terminal window and cd'ing into the directory the script was in. Just copy the script into every folder you want to use if from; it's got a tiny footprint. Here's the code:

set myPath to (do shell script "dirname " & quoted form of (POSIX path of (path to me) as string)) as string
tell application "Terminal"
  activate
  do script ("cd " & quoted form of myPath)
end tell
Paste this into AppleScript Editor and save it as an application. Copy it into each folder you'll want to use it with.

I recommend naming it something like " Terminal" (the space in front will make it float to the top of a list of files).

And, it will Just Work. Double-click the app and Terminal will open with a new window cd'd to the folder where you just were in Finder.

[crarko adds: I tested this, and it works as described. We've run hints of this type before; here is another method.]

Comments (25)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20110627065655730