2011-08-14 27 views
1

我有一個小的啓動腳本,在系統啓動時啓動一些應用程序。最近,我刪除了應用程序,每次啓動它時都會顯示一個瀏覽窗口以查找丟失的應用程序。有沒有辦法讓它忽略沒有應用程序 - 只需跳過它。applescript如何忽略瀏覽窗口如果應用程序未找到後「告訴應用程序X啓動」?

這裏是我試過:

try 
     tell application "junk2" to launch 
    on error 
     set myMessage to "Error launching " & appName 
    end try 

因此,所有我需要設置myMessage錯誤消息並繼續。如何進行?

感謝

回答

1

你需要「使用從應用方面」命令(谷歌它的詳細解釋)。如果您將applescript代碼保存爲應用程序,並且必須在具有該應用程序的計算機上創建該代碼,這將起作用。這兩件事情可以避免腳本在運行代碼的計算機上編譯,如果按照我的說明創建腳本,這將防止發生錯誤。所以在這個腳本中,我們使用mdfind來檢查應用程序是否存在於計算機上,如果是這樣的話啓動應用程序...

set appName to "TextWrangler.app" -- notice here I add .app to ensure the application itself is found with mdfind and not other types of documents 

set appPath to paragraphs of (do shell script "mdfind " & quoted form of appName) 
if appPath is {} then 
    return "The app does not reside on the system!" 
else 
    -- notice here I did not use the variable 
    using terms from application "TextWrangler" 
     tell application "TextWrangler" to launch 
    end using terms from 
end if 
+0

謝謝!那就是訣竅。 – sashk

相關問題