在 OS X 中,如何设置 AppleScript 来
- 打开一个新 iTerm2 选项卡
- 切换到目录
- 清除控制台
- 回显当前目录
我以前在常规终端上也遇到过类似的问题,但我甚至找不到 iTerm2 的脚本指南。
答案1
下面的操作几乎按照您的要求进行,但它会打开一个新窗口。
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text "cd ~/Desktop; clear; pwd"
end tell
end tell
(这是基于新的 iTerm 文档和以下答案,您应该点赞!)
答案2
如果 2020 年有人想寻找这个问题的答案,请参阅以下内容:
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text "cd ~/Desktop; clear; pwd"
end tell
end tell
答案3
我已经尝试过这个脚本,它对我有用。参考:https://iterm2.com/documentation-scripting.html
tell application "iTerm2"
tell current window
set newTab to (create tab with default profile)
tell current session of newTab
write text "cd ~/Documents; pwd"
end tell
end tell
end tell
答案4
目前还没有在 Mac 上实现,因此可能无法 100% 正常工作(经过改编我的这个答案)。
tell application "iTerm"
activate
set t to (make new terminal)
tell t
tell (make new session at the end of sessions)
exec command "cd Downloads"
exec command "clear"
exec command "pwd"
end tell
end tell
end tell
您可以将命令连接到
cd Downloads ; clear ; pwd