如何从AppleScript的推出X code的特定版本? [英] How do I launch a particular version of Xcode from Applescript?

查看:107
本文介绍了如何从AppleScript的推出X code的特定版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了X code,X code 3.2.3和X code4开发商preVIEW的两个版本。
如何从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?

推荐答案

而不是简单地用它的名字,即引用X code:

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

tell application "Xcode"
    ...
end tell

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

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

另请参见上的<一的的AppleScript语言指南节href=\"http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-SW2\"相对=nofollow>应用程序类。

一个更复杂的解决方案,包括为已安装在系统上的应用程序的所有版本的搜索发射服务数据库。然后,您可以通过编程挑一个具有所需版本:

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

这篇关于如何从AppleScript的推出X code的特定版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆