2009-01-30 13 views

Respuesta

10

Está bien ... Creo que he encontrado mi respuesta:

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 
+0

Great stuff. Una cosa a tener en cuenta es que el sistema operativo (al menos en 10.7.4) activa automáticamente Finder, con ventanas no minimizadas, una vez que se cierra la última aplicación. Si prefiere una vista limpia de su escritorio, puede minimizar todas las ventanas del Finder, 'tell application" System Events "para hacer clic (primer botón de cada ventana del proceso" Finder "cuya función es" minimizar el botón ")', y/o ciérrelos todos, 'diga a la aplicación" Buscador "que cierre cada ventana'. Si los cierra, minimizarlos primero evita el parpadeo. – mklement0

+0

Mientras usamos la propiedad 'name' de la clase de proceso _usually_ works, hay aplicaciones cuyo valor difiere del nombre de la aplicación como se muestra en la interfaz de usuario y según lo entiende la instrucción' tell application'. Por lo tanto, es mejor usar la propiedad 'displaying name' (aunque todavía puede haber casos en que incluso eso no funciona). Por lo tanto, la línea relevante anterior debe ser 'set process_list al nombre mostrado de cada proceso que sea visible'. – mklement0

0
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 
+1

Bienvenido a Stackoverflow. ¿Te importaría ampliar un poco tu respuesta para explicar cómo se resuelve el problema? – Daenarys

+0

esto cierra todas las aplicaciones visibles, excepto el buscador, de forma segura para que no cierre otros procesos en ejecución que puedan afectar los procesos de fondo de las computadoras. – Jeff

1
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 
0

Después de algunas google, me encontré con un mejor enfoque:

  • Se utiliza para construir background only la lista de aplicaciones inicial, en lugar de visible is true. La diferencia es que las otras secuencias de comandos fallarán para salir de una aplicación que se ha ocultado con ⌘H.
  • Proporciona una lista de exclusiones para que, por ejemplo, pueda evitar que el editor de scripts se cierre cada vez que pruebe el script.

Adaptado de a thread on 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 
Cuestiones relacionadas