2016-08-01 34 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(但不支持拆分選項卡)的高級功能。