1
tell application "Terminal"
    activate
    if windows is {} then reopen
    do script "ssh user@192.168.0.1" in window 1
end tell

如果有打开的窗口,我如何告诉苹果脚本也打开新窗口,因为它会破坏现有的窗口。

4

2 回答 2

2

这个比较干净...

tell application "Terminal"
    if not (exists window 1) then reopen
    activate
    do script "ssh user@192.168.0.1" in window 1
end tell
于 2013-09-22T13:25:42.107 回答
0

如果您不按索引定位窗口,它将每次打开一个新窗口。

例如,

tell application "Terminal"
    activate
    do script "ssh user@192.168.0.1"
end tell

或处理使用现有窗口重新打开。

tell application "System Events"
    if (count (processes whose bundle identifier is "com.apple.Terminal")) is 0 then
        tell application "Terminal"
            activate
            do script "ssh user@192.168.0.1" in window 0
        end tell
    else
        tell application "Terminal"
            do script "ssh user@192.168.0.1"
            activate
        end tell
    end if
end tell

更多想法在这里:http ://hintsforums.macworld.com/archive/index.php/t-68252.html

于 2013-09-22T10:30:26.523 回答