Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2014 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f16a46c327a14ec8a5b5 to your computer and use it in GitHub Desktop.
Save anonymous/f16a46c327a14ec8a5b5 to your computer and use it in GitHub Desktop.
Create a new tab in Terminal using bash and AppleScript.
new-tab ()
{
if [ "$#" -eq 1 ]; then
COMMAND="$1";
osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"clear && $COMMAND\" in front window" -e "end tell" > /dev/null;
else
if [ "$#" -eq 2 ]; then
COMMAND="$1";
TAB_NAME="$2";
osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"clear && name-tab '$TAB_NAME' && $COMMAND\" in front window" -e "end tell" > /dev/null;
else
echo -e "usage: $FUNCNAME command [tab_name]\n";
fi;
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment