2014-09-24 38 views
-1

正常工作,這個腳本是打開的微軟應用程序,然後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

回答

1

您遇到的問題是,告訴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

相關問題