Skip to content

Instantly share code, notes, and snippets.

@cjerdonek
Created May 20, 2012 20:56
Show Gist options
  • Save cjerdonek/2759506 to your computer and use it in GitHub Desktop.
Save cjerdonek/2759506 to your computer and use it in GitHub Desktop.
Initialize a new Terminal tab from the command-line (Mac OS X)
# Mac OSX: initialize a new Terminal tab from the Terminal command-line.
#
# Usage: osascript newtab.scpt TITLE PATH
#
# Summary:
#
# (1) opens a new terminal tab in the same window,
# (2) sets the title of the tab, and
# (3) cds into an initial directory.
#
# See also:
#
# http://stackoverflow.com/questions/7171725/open-new-terminal-tab-from-command-line-mac-os-x
#
on newTab(title, path)
tell app "System Events"
tell process "Terminal" to keystroke "t" using command down
end tell
tell application "Terminal"
activate
do script with command¬
"settitle " & title & "; " &¬
"cd " & path¬
in window 1
end tell
end newTab
on run argv
newTab(item 1 of argv, item 2 of argv)
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment