如何设置 AppleScript 以打开新的 iTerm2 选项卡并更改目录?

cwd*_*cwd 18 terminal iterm applescript macos

在 OS X 中,如何将 AppleScript 设置为

  • 打开一个新的 iTerm2 选项卡
  • 切换到目录
  • 清除控制台
  • echo 当前目录

我以前在普通终端上有类似的东西,但我什至找不到 iTerm2 的脚本指南。

slh*_*hck 16

Daniel 的解决方案以某种方式打开了一个新窗口 - 此外,该exec command语句无法按预期工作。一个必须write text相反。

此外,你必须使用

launch session "Default Session" 
Run Code Online (Sandbox Code Playgroud)

为了获得一个新标签。

以下执行您的要求:

tell application "iTerm"
    make new terminal
    tell the current terminal
        activate current session
        launch session "Default Session"
        tell the last session
            write text "cd ~/Downloads; clear; pwd"
        end tell
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)


小智 5

如果有人在 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
Run Code Online (Sandbox Code Playgroud)