问题描述
我安装了两个版本的 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?
推荐答案
不是简单地通过名称引用 Xcode,即:
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
另请参阅 应用程序类.
更复杂的解决方案是在 Launch Services 数据库中搜索系统上安装的所有应用程序版本.然后,您可以以编程方式选择具有所需版本的那个:
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 启动特定版本的 Xcode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!