使用特定目录在iTerm2中打开多个选项卡

时间:2013-11-19 04:32:20

标签: applescript

我希望能够执行AppleScript命令(从文件中),为特定目录打开新选项卡。

最好的方法是什么?

现在我有一个node.js脚本,我遍历每个目录并将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

然而,这并不是我喜欢做的事情(它会打开适量的标签,但是最后一个标签会写入所有内容)。

BONUS:如果您可以在打开所有标签后告诉我如何激活原始标签。

1 个答案:

答案 0 :(得分:1)

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