Skip to content

Instantly share code, notes, and snippets.

@raul
Created November 19, 2008 11:11
Show Gist options
  • Select an option

  • Save raul/26480 to your computer and use it in GitHub Desktop.

Select an option

Save raul/26480 to your computer and use it in GitHub Desktop.
#!/bin/sh -
#
# new_tab.sh v0.01
#
# Script to open a new tab on MacOSX's terminal from the command line
#
# Usage:
# new_tab.sh -> opens new tab in current directory
# new_tab.sh /tmp -> opens new tab in /tmp
# new_tab.sh /tmp ls -> opens new tab in /tmp and executes ls
#
# Credits:
# - Original code from Thomas Robinson: http://tlrobinson.net/blog/2008/10/23/open-new-terminal-tab/
# licensed under http://creativecommons.org/licenses/by-nc/3.0/us/
#
# - Quick & dirty modifications by Raul Murciano [raul@murciano.net] under the same license.
if [ $# == 0 ]; then
PATHDIR=`pwd`
else
PATHDIR=$1
NEXT_COMMAND=$2
fi
/usr/bin/osascript <<-EOF
activate application "Terminal"
tell application "System Events"
keystroke "t" using {command down}
end tell
tell application "Terminal"
repeat with win in windows
try
if get frontmost of win is true then
do script "cd $PATHDIR; clear" in (selected tab of win)
do script "$NEXT_COMMAND" in (selected tab of win)
end if
end try
end repeat
end tell
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment