iTerm2 中的新标签
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
到拆分创建的新session(新tab的下半部分):
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
、select File > Open Dictionary...
,然后打开 iTerm.app
。
还要考虑我的 ttab
CLI,它将选项卡/window 创建与 Terminal.app
和 iTerm2.app
的高级功能打包在一起(但它不支持拆分一个标签)。
我正在使用 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
到拆分创建的新session(新tab的下半部分):
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
、select File > Open Dictionary...
,然后打开 iTerm.app
。
还要考虑我的 ttab
CLI,它将选项卡/window 创建与 Terminal.app
和 iTerm2.app
的高级功能打包在一起(但它不支持拆分一个标签)。