开发者

applescript how to ignore Browse window if application not found afte "tell application X to launch"?

开发者 https://www.devze.com 2023-03-28 05:58 出处:网络
I\'ve got small launcher script, which launches some apps on system startup. Lately, I\'ve deleted on of the apps and every time it launches it shows me a browse window to loca开发者_StackOverflow社区

I've got small launcher script, which launches some apps on system startup. Lately, I've deleted on of the apps and every time it launches it shows me a browse window to loca开发者_StackOverflow社区te that missing app. Is there a way just to tell it to ignore if there is no app - just skip it.

Here is what I've tried:

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

So, all I need to set myMessage to error message and continue. How to proceed?

Thanks


You need the command "using terms from application" (google it for a detailed explanation). This will work if you save your applescript code as an application and you must create it on a computer which has the application. These two things will prevent the need for the script to compile on the computer running the code, which will prevent the error if you create it as I explained. So in this script we use mdfind to check if the application exists on the computer, and if so launch the app...

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

精彩评论

暂无评论...
验证码 换一张
取 消