iTerm2中的新选项卡



Im使用Iterm2版本Build 3.0.4我想创建别名以从命令行打开新的选项卡(在bash中)我试过这个代码:

    function tab () {
    osascript &>/dev/null <<EOF
activate application "iTerm"
    tell application "System Events" to keystroke "t" using command down
    tell application "iTerm" to tell session -1 of current terminal to write text "pwd"
EOF
}

但它不起作用。有人能解决这个版本(或更新版本)的问题吗?

iTerm2 v3的特性大大改进了AppleScript支持,因此您现在可以直接创建选项卡,而无需发送键击:

tab() {
    osascript &>/dev/null <<EOF
      tell application "iTerm"
        activate
        tell current window to set tb to create tab with default profile
        tell current session of current window to write text "pwd"  
      end tell
EOF
}

要水平拆分新选项卡(如按所示⇧⌘D),添加:

tell current session of current window to split horizontally with same profile

pwd写入拆分创建的新会话(新选项卡的下半部分):

tab() {
    osascript &>/dev/null <<EOF
      tell application "iTerm"
        activate
        tell current window to set tb to create tab with default profile
        tell current session of current window to set newSplit to split horizontally with same profile
        tell newSplit
          select
          write text "pwd"
        end tell    
      end tell
EOF
}

要浏览iTerm2的可用AppleScript命令,请打开Script Editor.app,选择File > Open Dictionary...,然后选择iTerm.app

还要考虑我的ttab CLI,它将选项卡/窗口创建以及Terminal.appiTerm2.app的高级功能打包在一起(但不支持拆分选项卡)。

tell application "iTerm"
activate
tell current window to create tab with default profile
tell session of current tab of current window
    select
    write text "pwd"
end tell

结束告诉

相关内容

  • 没有找到相关文章

最新更新