Open new Terminal window in current (or other specified) directory

A lot of times I find myself wanting to open another (Mac OS X) Terminal window in the same directory as my current one. This little shell script, which executes a little AppleScript, makes that trivial:

#!/bin/sh

if [ $# -ne 1 ]; then
    PATHDIR=`pwd`
else
    PATHDIR=$1
fi

osascript -e "tell application \"Terminal\"" -e "do script \"cd $PATHDIR\"" -e "end tell"

Save this script somewhere in your $PATH with executable permissions. Now instead of hitting Command-N then typing “cd really/long/path/to/your/current/directory”, you can simply type the name of the script (I used “term”):

term

Chain them together to open multiple windows. The following would open three new windows with the same current directory:

term; term; term

It can also take an optional directory path argument to override the current directory:

term /System/Library/
blog comments powered by Disqus


Warning: include(/home/tlrobinson/tlrobinson.net/_footer-analytics.php) [function.include]: failed to open stream: No such file or directory in /home/tlrobinson/tlrobinson.net/blog/wp-content/themes/clean-look-150/footer.php on line 13

Warning: include() [function.include]: Failed opening '/home/tlrobinson/tlrobinson.net/_footer-analytics.php' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/tlrobinson/tlrobinson.net/blog/wp-content/themes/clean-look-150/footer.php on line 13