Apple脚本错误

时间:2012-09-05 11:22:52

标签: applescript

我想在Application文件夹中搜索已安装的应用程序,但下面的代码无法执行相同操作,请提示我正确的方法。

tell application "Finder"

    if folder "Applications" of startup disk contains "Safari" then
        return true
    else
        return false
    end if
end tell

我为现有应用程序获取了代码,如果应用程序不存在则在这种情况下,AppleScript会弹出一个名为“选择应用程序”的对话框,询问“AppYouDontHave在哪里?”,请更正。< / p>

修改后的代码

tell application "Finder"
    if application "Safari" exists then
        tell application "Safari"
            set safariVersion to version
            return version
        end tell
    else
        false
    end if
end tell

1 个答案:

答案 0 :(得分:0)

获取ID

get id of application "Safari"

返回“com.apple.Safari”

  try
        exists application id "com.apple.Safari"
    on error
        return false
    end try

这应该解决您修改过的评论:

try
    tell application "Finder" to set theApp to get first item of folder "Applications" of the startup disk whose name is "Safari.app"
on error
    return false
end try
version of theApp