我安装了两个版本的Xcode,Xcode 3.2.3和Xcode4开发人员预览版。 如何从Applescript确保选择了3.2.3版本?
答案 0 :(得分:3)
而不是简单地通过名称引用Xcode,即:
tell application "Xcode"
...
end tell
您还可以通过其完整的POSIX路径引用特定版本的应用程序,即:
tell application "/Developer/Applications/Xcode 3.2.3.app"
...
end tell
另请参阅application class上的AppleScript语言指南部分。
更复杂的解决方案是在Launch Services数据库中搜索系统上安装的应用程序的所有版本。然后,您可以以编程方式选择具有所需版本的那个:
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
答案 1 :(得分:2)
您可以通过其ID启动应用程序。也许两个版本会有不同的ID。
tell application id "com.apple.AddressBook"
-- do something
end tell
您可以通过此获取应用程序的ID ...
tell application "Finder" to return id of (choose file)