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
(但不支持拆分选项卡)的高级功能。