2016-08-01 36 views
4

进出口使用Iterm2版本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 
} 

,但它不是”不工作。任何人都可以用这个版本(或更新版本)解决问题吗?

回答

3

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

另请考虑我的CLI,其中包含选项卡/窗口创建以及Terminal.appiTerm2.app(但不支持拆分选项卡)的高级功能。