Applescript 在iTerm2中打开具有特定目录的多个选项卡

Applescript 在iTerm2中打开具有特定目录的多个选项卡,applescript,Applescript,我希望能够执行一个AppleScript命令(从一个文件),它将打开特定目录的新选项卡 最好的方法是什么 现在我有一个node.js脚本,我循环遍历每个dir并将dir传递给这个AppleScript文件: on run arg set p to arg's first item set g to "cd " & p & "; clear; pwd" tell application "iTerm" make new termin

我希望能够执行一个AppleScript命令(从一个文件),它将打开特定目录的新选项卡

最好的方法是什么

现在我有一个node.js脚本,我循环遍历每个dir并将dir传递给这个AppleScript文件:

on run arg    
    set p to arg's first item
    set g to "cd " & p & "; clear; pwd"

    tell application "iTerm"
        make new terminal
        tell the current terminal
            activate current session
            launch session "Default Session"
            tell the last session to write text g
        end tell
    end tell
end run
然而,这并不是我喜欢的(它打开了适当数量的选项卡,但最后一个选项卡会将所有内容写入其中)


奖励:如果您能告诉我如何在打开所有选项卡后激活原始选项卡。

最好总是使用“anyFilepath的引用形式”而不是“anyFilepath”。最好总是使用“anyFilepath的引用形式”而不是“anyFilepath”。
tell application "iTerm"
    if exists current terminal then
        set t to current terminal
    else
        set t to make new terminal
    end if
    tell (launch session "Default Session") of t to write text "cd /etc;clear;pwd"
    tell (launch session "Default Session") of t to write text "cd /var;clear;pwd"
    activate
end tell