Mac OS X Terminal TabName Script

| Comments

A simple set of functions that can be used in bash to adjust the tab names or create new tabs in Mac OS X’s Terminal application. The syntax is just

tabname "<new name of current tab>"

or

new_tab "<new name of tab>" "<command to run>"

The original code was posted on Original Stackoverflow Article

## add to the end of ~/.profile or ~/.bash_profile
tabname() {
printf "\e]1;$1\a"
}
new_tab() {
TAB_NAME=$1
COMMAND=$2
osascript \
-e "tell application \"Terminal\"" \
-e "tell application \"System Events\" to keystroke \"t\" using {command down}" \
-e "do script \"printf '\\\e]1;$TAB_NAME\\\a'; $COMMAND\" in front window" \
-e "end tell" > /dev/null
}

Comments