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.app
和iTerm2.app
(但不支持拆分選項卡)的高級功能。