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

前端 未结 13 2214
醉话见心
醉话见心 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:42

    The keyboard shortcut cmd-t opens a new tab, so you can pass this keystroke to OSA command as follows:

    osascript -e 'tell application "System Events"' -e 'keystroke "t" using command down' -e 'end tell'

    0 讨论(0)
  • 2020-12-02 04:42

    If you are using iTerm this command will open a new tab:

    osascript -e 'tell application "iTerm" to activate' -e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down'
    
    0 讨论(0)
  • 2020-12-02 04:43

    when you are in a terminal window, command + n => opens a new terminal and command + t => opens a new tab in current terminal window

    0 讨论(0)
  • 2020-12-02 04:43

    What about this simple snippet, based on a standard script command (echo):

    # set mac osx's terminal title to "My Title"
    echo -n -e "\033]0;My Title\007"
    
    0 讨论(0)
  • 2020-12-02 04:46

    Here's how it's done by bash_it:

    function tab() {
      osascript 2>/dev/null <<EOF
        tell application "System Events"
          tell process "Terminal" to keystroke "t" using command down
        end
        tell application "Terminal"
          activate
          do script with command "cd \"$PWD\"; $*" in window 1
        end tell
    EOF
    }
    

    After adding this to your .bash_profile, you'd use the tab command to open the current working directory in a new tab.

    See: https://github.com/revans/bash-it/blob/master/plugins/available/osx.plugin.bash#L3

    0 讨论(0)
  • 2020-12-02 04:52
    osascript -e 'tell app "Terminal"
       do script "echo hello"
    end tell'
    

    This opens a new terminal and executes the command "echo hello" inside it.

    0 讨论(0)
提交回复
热议问题