tell application "Terminal"
activate
if windows is {} then reopen
do script "ssh user@192.168.0.1" in window 1
end tell
如果有打开的窗口,我怎么能告诉苹果脚本,打开新窗口,因为它会破坏现有的窗口。
答案 0 :(得分: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
答案 1 :(得分:0)
如果您没有按索引定位窗口,则每次都会打开一个新窗口。
e.g,
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