告诉应用程序打开,然后退出时不是AppleScript的

问题描述:

正常工作,这个脚本是打开的微软应用程序,然后3秒告诉应用程序打开,然后退出时不是AppleScript的

tell application "Finder" 
set myFolder to ((startup disk as text) & "Applications:Microsoft Office 2011") as alias 
set myFiles to (every item of myFolder) as alias list 
open myFiles 
end tell 

delay 3 

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 
end tell 

但是当我运行该脚本,它在这之后停止后退出。 (编辑),它似乎关闭每一个应用程序除了Microsoft应用程序

tell application "Finder" 
set myFolder to ((startup disk as text) & "Applications:Microsoft Office 2011") as alias 
set myFiles to (every item of myFolder) as alias list 
open myFiles 

都打开和关闭应用程序的脚本工作的伟大分别,但我似乎不知道如何加入他们的行列。如果有人知道这是为什么发生,那会很好。由于

+0

你怎么知道后“开MYFILES”停止? *延迟3 *没有可见的效果。您可以尝试将一些*显示对话框“Hello 1”*等放入脚本中,以确切查看它停止的位置。 – 2014-09-24 23:28:20

+0

hmm well显示对话框在“打开myFiles”后工作,但我知道它停止的原因是因为当我运行脚本时,在“打开myFiles”后不久,带有“记录,停止,运行,编译”按钮的苹果脚本工具栏返回当你还没有运行脚本的时候,它的样子(对不起,我真的不知道该怎么解释,希望你能理解) – 2014-09-25 02:51:30

您遇到的问题是,告诉Finder打开一个应用程序是在脚本asyncrynous。意思是,直到应用程序加载前,它才会完成。使用延迟命令永远不会得到正确的结果。我建议使用“告诉应用程序xxx激活”,然后再继续。而且,它使您的脚本方式更清洁。

property myApps : {"Microsoft Word", "Microsoft Excel"} 

repeat with thisApp in myApps 
    try 
     tell application thisApp to activate 
    end try 
end repeat 

-- do whatever you need after all are open 

repeat with thisApp in myApps 
    try 
     tell application thisApp to quit 
    end try 
end repeat 

如果你想戒烟,除了查找每一个可见的应用程序,您还可以添加

tell application "Finder" to set myApps to name of (every process whose ((visible is true) and (name is not "Finder"))) 
+0

我会尝试一下,让你知道,谢谢你帮助一个新的学习者: )与我已经问过的所有其他问题,感谢它 – 2014-09-25 03:31:26

+0

所以我需要键入所有应用程序,我想打开属性myApps:{“应用程序打开}} 以及我会在哪里添加 '告诉APPLICATION“Finder”将myApps设置为((((可见为真)和(名称不是“Finder”))的每个进程的名称) – 2014-09-25 03:34:48

+0

是的,所有的你需要的是应用程序名称,每个名称都用引号括起来,用逗号分隔每个名称。如{“Microsoft Word”,“Microsoft Excel”,“Microsoft Powerpoint”,“Microsoft Outlook”} – jweaks 2014-09-25 03:36:55