繁体   English   中英

Applescript无法在新窗口中打开应用

[英]Applescript failing to open app in new window

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

我怎么能告诉苹果脚本是否有打开的窗口,也要打开新窗口,因为它会破坏现有的窗口。

这比较干净...

tell application "Terminal"
    if not (exists window 1) then reopen
    activate
    do script "ssh user@192.168.0.1" in window 1
end tell

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

例如,

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM