“清除缓冲区”是Iterm2的“编辑”菜单(命令K)下的菜单选项。我想编写此脚本以清除Iterm的缓冲区。
根据其他网站的建议,我尝试过
tell theSession
select
tell application "System Events" to tell process "iTerm2"
click menu item "Clear Buffer" of menu 1 of menu bar item "Edit" of menu
bar 1
end tell
end tell
我也尝试过
tell theSession
select
tell application "System Events"
delay 0.1
keystroke "L" using command down
end tell
end tell
似乎都没有做任何事情。有什么想法吗?
答案 0 :(得分:0)
使用 iTerm2 Build 3.1.7 (默认键盘快捷键)在 macOS 10.13.5 下进行了测试。 清除缓冲区 命令为⌘K,如下图所示。
以下示例 AppleScript 代码将激活 iTerm ,并在最前面的窗口中执行操作以清除缓冲区:
tell application "System Events"
click UI element "iTerm" of list 1 of application process "Dock"
delay 0.25
try
keystroke "k" using command down
end try
end tell
或使用:
tell application "iTerm" to activate
delay 0.25
tell application "System Events"
try
keystroke "k" using command down
end try
end tell
k
。如果您已修改清除缓冲区键盘快捷键以使用⌘L,请使用小写 l
。