我安装了两个版本的Xcode,Xcode3.2.3和Xcode4开发者预览版。如何从Applescript中确保选择了3.2.3版本?
发布于 2010-08-20 23:39:10
而不是简单地通过其名称引用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发布于 2010-08-21 01:14:02
您可以通过id启动应用程序,如下所示。也许这两个版本会有不同的id。
tell application id "com.apple.AddressBook"
-- do something
end tell你可以用下面的代码获得一个应用程序的id。
tell application "Finder" to return id of (choose file)https://stackoverflow.com/questions/3531156
复制相似问题