Quittez toutes les applications en utilisant Applescript?
-
20-08-2019 - |
Question
Comment pourrais-je quitter toutes les applications utilisateur en cours d'exécution à l'aide d'Applescript?
La solution
Ça va ... je pense avoir trouvé ma réponse:
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
Autres conseils
Après quelques recherches sur Google, j'ai trouvé une meilleure approche:
- Il utilise
background only
pour construire la liste d'applications initiale, plutôt quevisible is true
La différence est que les autres scripts vont échouer pour quitter une application cachée avec & # 8984; H. - Il fournit une exclusion liste afin que, par exemple, vous puissiez empêcher votre éditeur de script quitter à chaque fois que vous testez le script.
Adapté de un fil de discussion sur MacScripter .
-- get list of open apps
tell application "System Events"
set allApps to displayed name of (every process whose background only is false) as list
end tell
-- leave some apps open
set exclusions to {"AppleScript Editor", "Automator", "Finder", "LaunchBar"}
-- quit each app
repeat with thisApp in allApps
set thisApp to thisApp as text
if thisApp is not in exclusions then
tell application thisApp to quit
end if
end repeat
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow