1

我想查明在可能安装了一个或多个不同版本的 Firefox 的 Mac 上是否安装了特定版本的 Firefox。我不能简单地使用version of application "Firefox",因为那样我可能会错过 Firefox 的替代安装。到目前为止,我的 Applescript 代码是:

tell application "Finder"
    set firefox_list to paragraphs of (do shell script "find /Applications -name Firefox.app")
    repeat with ff_installed in firefox_list
        -- get version
        set ff_ins_info to property list file (POSIX path of ff_installed & "/Contents/Info.plist")
        set ff_ins_version to (value of property list item "Bundle version" of ff_ins_info)
        display dialog ff_ins_version
    end repeat
end tell

不幸的是,当我尝试编译时收到一条错误消息:Syntax Error: Expected expression but found “property”. 我能做出的最好的判断是 Applescript 似乎无法识别property list file为对象。据我了解,这应该在 10.5 之后起作用。

我考虑过使用 Apple 的 PlistBuddy 实用程序编写一个 shell 脚本来查找版本号,但这似乎比这种方法更复杂。我离开了吗grep直接通过 Plist XML 进行 ing?

在此先感谢您的任何建议!

4

1 回答 1

1

我进行了 3 处更改以使其正常工作:

  1. 替换tell application "Finder"tell application "System Events"
  2. 被排除在外POSIX path of
  3. 替换Bundle versionCFBundleVersion

这是最终版本

tell application "System Events"
    set firefox_list to paragraphs of (do shell script "find /Applications -name Firefox.app")
    repeat with ff_installed in firefox_list
        -- get version
        set ff_ins_info to property list file (ff_installed & "/Contents/Info.plist")
        set ff_ins_version to (value of property list item "CFBundleVersion" of ff_ins_info)
        display dialog ff_ins_version
    end repeat
end tell
于 2013-08-06T18:38:33.843 回答