查找使用AppleScript安装了Mac OSX版本
-
20-08-2019 - |
题
如何才能找到这OSX版本安装在我的Mac上通过使用AppleScript?我想基于版本编程安装应用程序,运行不同的PKG文件。
由于
解决方案
我无法在Mac上,所以有可能会出现在脑海只是执行一个shell命令查询OS版本更好的方式来做到这一点,但第一种方法。
http://developer.apple.com/technotes/tn2002/tn2065。 HTML#TNTAG2
http://developer.apple.com/文档/达尔文/参考/手册页/ MAN1 / sw_vers.1.html
基于这些引用,你可能想要做的是这样的:
set os_version to do shell script "sw_vers -productVersion"
其他提示
下面是如何获得的AppleScript OSX版本,使用内置的功能:
set sysinfo to system info set osver to system version of sysinfo
在OS X小牛结果是 “10.9”。
一衬垫:set osver to system version of (system info)
可以使用获取OS的版本作为显示字符串:
set _versionString to system version of (system info)
如果您想与此相比,另一种版本,一定要使用的 considering numeric strings
:
considering numeric strings
set _newEnough to _versionString ≥ "10.9"
end considering
否则,可以碰到的问题,如“10.4.11”小于“10.4.9”或“10.10”小于“10.9”。
您也可以使用system attribute
。这可以让你得到的版本号为整数,这样你就不用担心比较点分隔的字符串:
set _versionInteger to system attribute "sysv" -- 4240 == 0x1090 (Mac OS X 10.9)
set _isMavericksOrBetter to (system attribute "sysv") ≥ 4240 -- 0x1090
set _isMountainLionOrBetter to (system attribute "sysv") ≥ 4224 -- 0x1080
set _isLionOrBetter to (system attribute "sysv") ≥ 4208 -- 0x1070
您还可以使用system attribute
获得单独版本的组件,而不必解析字符串:
set _major to system attribute "sys1" -- 10
set _minor to system attribute "sys2" -- 9
set _bugFix to system attribute "sys3" -- 0
您可以从Finder应用程序获得的版本,以及
tell application "Finder"
set os_version to version
end tell
display dialog os_version
在我的机器这个显示 “10.5.8”。
我不是太熟悉使用AppleScript,但据我所知,你可以获取从与sw_vers命令外壳版本的一些信息。例如:
Macintosh:~ udekel$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.5.6
BuildVersion: 9G55
如果您可以阅读和分析,从AppleScript的,这可能是一个解决方案,但我敢肯定,必须有一些更优雅。
尝试沿着这些路线的东西:
tell application "Terminal"
activate
set theVersion to do script with command "sw_vers -productVersion"
end tell
编辑:有人指出,这确实打开终端,这可能不是你想要的行为。
这为我工作
set OSVersion to system version (system info)
if OSVersion as string < "10.9" or OSVersion as string > "10.9.5" then
- Add code to execute if condition met
else
- Add code to execute if condition not met
end if