2013-08-22 43 views
7

AppleScript新手问题再次:)我想创建一个小的applescript,这将允许我从当前运行的应用程序列表中选择多个项目,然后退出这些选定的应用程序。类似这样的工作,但不必点击每个对话框,从列表中选择会更容易。Applescript获取正在运行的应用程序的列表?

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 

任何和所有的帮助将不胜感激!

谢谢!

回答

11

试试这个:

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

就像一个魅力!我最后的问题是,如果没有killall命令,你会如何做到这一点?有点像,告诉应用程序selectedProcesses退出。谢谢! – user2555399

+0

查看上面Parag脚本的底部。 – user2555399

+0

编辑添加Parag的脚本部分。 –

1

你可以试试这个

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

脚本的顶部并不适用于我,但底部却做到了!谢谢! – user2555399

+0

你有错误吗? –

1

& (name of every process whose (name is "AppName")可以添加到Michele Percich'sParag Bafna's解决方案,包括由名特定菜单栏的应用。

tell application processName to quit可以用来代替do shell script "Killall " & quoted form of processName

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

你可以使用这个脚本是简单得多

tell application "Finder" 
    get the name of every process whose visible is true 
end tell 
相关问题