[英]new tab in iTerm2
我正在使用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.app
和iTerm2.app
高级功能(但它不支持拆分选项卡)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.