如何从 Applescript 启动特定版本的 Xcode?

发布于 2024-09-14 21:27:17 字数 83 浏览 9 评论 0 原文

我安装了两个版本的 Xcode:Xcode 3.2.3 和 Xcode4 开发人员预览版。 如何确保 Applescript 选择了 3.2.3 版本?

I have two versions of Xcode installed, Xcode 3.2.3 and the Xcode4 developer preview.
How do I ensure from Applescript that the 3.2.3 version is picked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不知所踪 2024-09-21 21:27:17

除了简单地通过名称引用 Xcode,即:

tell application "Xcode"
    ...
end tell

您还可以通过完整的 POSIX 路径引用应用程序的特定版本,即:

tell application "/Developer/Applications/Xcode 3.2.3.app"
    ...
end tell

另请参阅 应用程序类

更复杂的解决方案涉及在启动服务数据库中搜索系统上安装的应用程序的所有版本。然后,您可以通过编程方式选择具有所需版本的版本:

property pLSRegisterPath : "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
property pAppBundleID : "com.apple.Xcode"
property pAppRequiredVersion : "3.2.3"

set theAppPaths to every paragraph of (do shell script pLSRegisterPath & " -dump | grep --before-context=2 \"" & pAppBundleID & "\" | grep --only-matching \"/.*\\.app\"")

set xcodeApp to missing value
repeat with theAppPath in theAppPaths
    try
        if (version of application theAppPath) = pAppRequiredVersion then
            set xcodeApp to application theAppPath
            exit repeat
        end if
    end try
end repeat

if xcodeApp = missing value then
    error "Needed application version not installed."
end if

using terms from application "Xcode"
    tell xcodeApp
        activate
    end tell
end using terms from

Instead of simply referencing Xcode by its name, i.e.:

tell application "Xcode"
    ...
end tell

you can also reference a particular version of an application by its full POSIX path, i.e.:

tell application "/Developer/Applications/Xcode 3.2.3.app"
    ...
end tell

Also see the AppleScript language guide section on the application class.

A more complex solution involves searching the Launch Services database for all the versions of an application that are installed on the system. You can then programmatically pick the one with the required version:

property pLSRegisterPath : "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
property pAppBundleID : "com.apple.Xcode"
property pAppRequiredVersion : "3.2.3"

set theAppPaths to every paragraph of (do shell script pLSRegisterPath & " -dump | grep --before-context=2 \"" & pAppBundleID & "\" | grep --only-matching \"/.*\\.app\"")

set xcodeApp to missing value
repeat with theAppPath in theAppPaths
    try
        if (version of application theAppPath) = pAppRequiredVersion then
            set xcodeApp to application theAppPath
            exit repeat
        end if
    end try
end repeat

if xcodeApp = missing value then
    error "Needed application version not installed."
end if

using terms from application "Xcode"
    tell xcodeApp
        activate
    end tell
end using terms from
甜点 2024-09-21 21:27:17

您可以像这样通过应用程序的 id 启动应用程序。也许两个版本会有不同的 id。

tell application id "com.apple.AddressBook"
    -- do something
end tell

你可以用这个来获取应用程序的ID...

tell application "Finder" to return id of (choose file)

You can launch an application by its id like this. Maybe the two version will have different id's.

tell application id "com.apple.AddressBook"
    -- do something
end tell

You can get an application's id with this...

tell application "Finder" to return id of (choose file)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文