Open new Terminal Tab from command line (Mac OS X)

前端 未结 13 2304
醉话见心
醉话见心 2020-12-02 04:19

Is it possible to open a new tab in Mac OS X\'s terminal from the command line in a currently opened tab?

I know that the keyboard shortcut to open a new tab in Term

13条回答
  •  甜味超标
    2020-12-02 04:36

    I added these to my .bash_profile so I can have access to tabname and newtab

    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
    }
    

    So when you're on a particular tab you can just type

    tabname "New TabName"
    

    to organize all the open tabs you have. It's much better than getting info on the tab and changing it there.

提交回复
热议问题