2017-07-14 107 views
1

我已經關閉所有應用一個AppleScript:如何使用AppleScript關閉所有隱藏的應用程序?

tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder" 
    repeat with closeall in quitapps 
    quit application closeall 
end repeat 

它工作得很好。它退出所有打開的應用程序。

我的問題是我想修改這個腳本來關閉只隱藏的應用程序。出於某種原因,蘋果公司隱藏了所有蘋果公司製作的應用程序,沒有活動窗口,最終它開始吃掉我的內存。

什麼我認爲是,如果我只是改變線whose visible is truewhose visible is false我會得到這樣的結果。

不太:

Weird pop-up window

我甚至不知道這個窗口應該是的,所以我剛打取消。

好吧,它再次彈出。原來劇本炸彈爆炸之前我必須四次擊中取消。

有什麼辦法可以退出所有隱藏的應用程序,同時打開可見的應用程序?

(獎勵積分,如果你能解釋一下上面彈出。)

如果它的確與衆不同,我運行的是最新版本的OSX的。

回答

1

visible設置爲false會影響所有進程 - 即使沒有GUI的進程/應用程序。如果進程不是應用程序(.app),則出現應用程序選擇器。

添加支票background only,它僅影響具有GUI的應用程序。

tell application "System Events" to set quitapps to name of every application process whose visible is true and background only is false and name is not "Finder" ... 
+0

這與我所尋找的*正好相反。它會退出每個打開並且*不*隱藏的應用程序。我試圖修改這個行,「其可見性是錯誤的,背景只是假的」,它什麼也沒做。將其修改爲「其可見性爲假並且背景爲真」只需重新啓動我的碼頭即可。他們都離開了隱藏的應用程序。 – DonielF

+0

系統事件中的'可見'意味着'不隱藏'和'僅背景'意味着沒有GUI或「不是應用程序」的無臉應用程序。只有應用程序('。應用程序)迴應'退出'命令 – vadian

+0

好吧,但這仍然沒有做我想要的。 – DonielF

0

如果我理解正確,你是在談論如何當你按下紅色的關閉按鈕,它只是關閉應用程序的窗口,而不是應用程序本身,所以它只是離開了那裏仍處於打開狀態。

在這種情況下,你可以使用這個腳本我做了,現在看來,這完美的作品:

-- Get open apps 
tell application "System Events" to set openApps to name of every application process whose background only is false and name is not "Finder" 

-- Do this for every open app 
repeat with openApp in openApps 
    tell application openApp 
     -- Tell application to quit if it doesn't have any open windows 
     if (count of windows) is less than or equal to 0 then quit 
    end tell 
end repeat 
+0

我不瞭解你,但是當我運行它時,它根本不起作用。如果應用程序處於隱藏狀態,它仍然會將窗口識別爲開啓。如果所有窗口都關閉,但應用程序已打開,則應用程序仍然不會關閉。 – DonielF

+0

查看'openApps'和'count of windows',並打開一個應用程序,但沒有打開窗口,告訴我結果。 – Kamdroid

0

OSX沒有「隱藏」的應用程序。他們只是不活躍,或沒有任何文件打開。隱藏的應用程序是Command-H通常完成的一個非常具體的過程。應用程序不會以這種方式隱藏自己。

與其試圖關閉沒有窗口的應用程序,不如使用文檔計數來確定是否關閉應用程序。

tell application "SomeApp" if count of documents = 0 then quit 
相關問題