Open a new tab on Terminal with the same path (on Mac OS X)

While working on the command-line, we always find ourselves in situations where we have to open a new tab and cd to the path we were working on.

On a Mac, we can use some Applescript to help with that.

Paste it to your ~/.profile:


# open a new tab on Terminal with the current working dir
function newtab {
	osascript -e "
		tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down
		tell application \"Terminal\" to do script \"cd \\\"$(PWD)\\\"\" in selected tab of the front window
	" > /dev/null 2>&1
}

Now you just need to type “newtab”

About these ads
Open a new tab on Terminal with the same path (on Mac OS X)

4 thoughts on “Open a new tab on Terminal with the same path (on Mac OS X)

    1. Arach says:

      Thanks for the tip.
      The cd part does not work on my system when there is a space in the path, though.
      So I changed the script to accommodate for space in the path, as follows :

      # open a new tab on Terminal with the current working dir
      function newtab {
      osascript -e ”
      tell application \”System Events\” to tell process \”Terminal\” to keystroke \”t\” using command down
      tell application \”Terminal\” to do script \”cd \\\”$(PWD)\\\”\” in selected tab of the front window
      ” > /dev/null 2>&1
      }

      and now it works. Just wanted to share this with people who might have the same problem.

      Arach

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s