簡體   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