首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Applescript启动特定版本的Xcode?

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

Stack Overflow用户
提问于 2010-08-20 21:19:24
回答 2查看 1.1K关注 0票数 0

我安装了两个版本的Xcode,Xcode3.2.3和Xcode4开发者预览版。如何从Applescript中确保选择了3.2.3版本?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-08-20 23:39:10

而不是简单地通过其名称引用Xcode,即:

代码语言:javascript
复制
tell application "Xcode"
    ...
end tell

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

代码语言:javascript
复制
tell application "/Developer/Applications/Xcode 3.2.3.app"
    ...
end tell

另请参阅application class上的AppleScript语言指南部分。

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

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2010-08-21 01:14:02

您可以通过id启动应用程序,如下所示。也许这两个版本会有不同的id。

代码语言:javascript
复制
tell application id "com.apple.AddressBook"
    -- do something
end tell

你可以用下面的代码获得一个应用程序的id。

代码语言:javascript
复制
tell application "Finder" to return id of (choose file)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3531156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档