Bash Script – Opening a Terminal Window to a Specific Directory

bashcommand linefilesystemscriptterminal

How can I write a bash script in Mac OS X that opens a Terminal window in a specific directory? I'd assume something like:

open /Applications/Utilities/Terminal.app

But that does nothing (maybe it's loading the Terminal application which is already open instead of launching a new Terminal window). And of course it doesn't cd into a directory as I haven't specified that…

Best Answer

Here is a small script I knocked up :

#!/usr/bin/osascript
on run argv
  set dir to quoted form of (first item of argv)
  tell app "Terminal" to do script "cd " & dir
end run

If you save this and make it executable

chmod +x script_filename

and then run it

script_filename ~/Desktop

then it will open up a new terminal window and change to the directory in the argument.