2013-08-22 7 views
7

Applescript Newbie Frage wieder :) Ich versuche, ein kleines AppleScript erstellen, mit dem ich mehrere Elemente aus einer Liste der derzeit ausgeführten Anwendungen auswählen und dann diese ausgewählten Anwendungen beenden kann. So etwas funktioniert, aber anstatt auf jeden Dialog klicken zu müssen, wäre es viel einfacher, aus einer Liste zu wählen.Applescript get Liste von laufenden apps?

tell application "System Events" 
repeat with p in every process 
    if background only of p is false then 
     display dialog "Would you like to quit " & name of p & "?" as string 
    end if 
end repeat 
end tell 

Alle und alle Hilfe würde sehr geschätzt werden!

Danke!

Antwort

11

Try this:

tell application "System Events" 
    set listOfProcesses to (name of every process where background only is false) 
    tell me to set selectedProcesses to choose from list listOfProcesses with multiple selections allowed 
end tell 
--The variable `selectedProcesses` will contain the list of selected items. 
repeat with processName in selectedProcesses 
    do shell script "Killall " & quoted form of processName 
end repeat 
+0

Arbeiten viel einfacher ist !!! Meine letzte Frage ist, wie würdest du das ohne den killall Befehl machen? In gewisser Weise, sagen Sie der Anwendung selectedProcesses zum Beenden. Vielen Dank! – user2555399

+0

Siehe den unteren Teil von Parag's Skript oben. – user2555399

+0

Bearbeitet den Parag-Skript-Teil. –

1

Sie können versuchen, diese

tell application "System Events" 
     set AppName to name of every process whose background only is false 
     choose from list AppName OK button name "Ok" cancel button name "Cancel" 
    end 
5
tell application "System Events" 
    set processList to get the name of every process whose background only is false 
    set processNameList to choose from list processList with prompt "Select process to quit" with multiple selections allowed 
    if the result is not false then 
     repeat with processName in processNameList 
      do shell script "Killall " & quoted form of processName 
     end repeat 
    end if 
end tell 

enter image description here

+0

Der obere Teil Ihres Skripts funktionierte nicht für mich, aber der untere Teil tat es! Vielen Dank! – user2555399

+0

Erhalten Sie einen Fehler? –

1

& (name of every process whose (name is "AppName") können Michele Percich's und Parag Bafna's Lösungen hinzugefügt werden, um bestimmte Menüleiste Anwendungen mit Namen enthalten .

tell application processName to quit kann anstelle von do shell script "Killall " & quoted form of processName verwendet werden.

tell application "System Events" 
    set processList to ¬ 
     (name of every process where background only is false) & ¬ 
     (name of every process whose ¬ 
      (name is "AppName") or ¬ 
      (name is "AnotherAppName")) 
    tell me to set selectedProcesses to choose from list processList with prompt "Select process(es) to quit:" with multiple selections allowed 
end tell 
if the result is not false then 
    repeat with processName in selectedProcesses 
     tell application processName to quit 
    end repeat 
end if 
2

können Sie dieses Skript verwenden, die

wie ein Zauber
tell application "Finder" 
    get the name of every process whose visible is true 
end tell 
Verwandte Themen