System version
Last modification: Monday, August 25, 2008 12:47 amReturns a record containing information about the current system version.
Returned keys
__major (integer)The major version as integer
__minor (integer)
The minor version as integer
__revision (integer)
The revision as integer
__string (string)
Full version string
Function Calls
systemVersion()Implementation
on systemVersion()try
-- Use system_profiler command line tool to get the information about the system version
set _spOutput to paragraph 1 of (do shell script "system_profiler SPSoftwareDataType -detailLevel mini | grep 'System Version: '")
-- Remove the label "System Version" from the line
set _prvDlmt to AppleScript's text item delimiters
set AppleScript's text item delimiters to "System Version: "
set _versionString to text item 2 of _spOutput
set AppleScript's text item delimiters to _prvDlmt
-- Find the position of the first numerical character
set _firstNumPosition to false
repeat with _i from 1 to count of _versionString
try
get (character _i of _versionString) as integer
set _firstNumPosition to _i
exit repeat
end try
end repeat
if _firstNumPosition is false then error "No numerical character found."
-- Break the string at the position of the first numerical character
set _prvDlmt to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set _versionString to characters _firstNumPosition thru -1 of _versionString as string
-- Get the text before first space
set AppleScript's text item delimiters to " "
set _versionString to text item 1 of _versionString as string
-- Get the text before first space
set AppleScript's text item delimiters to "."
copy (text items of _versionString) to {_major, _minor, _revision}
set AppleScript's text item delimiters to _prvDlmt
-- Transform strings to integers
set _major to _major as integer
set _minor to _minor as integer
set _revision to _revision as integer
on error _eMessage
-- Reset the delimiters
set AppleScript's text item delimiters to _prvDlmt
-- This alternative will work for systems that do not support the do shell script command
set _hex to system attribute "sysv"
-- Get the revision
set _revision to _hex mod 16
set _hex to _hex div 16
-- Get the minor version
set _minor to _hex mod 16
set _hex to _hex div 16
-- Get the major version
set _major1 to _hex mod 16 as string
set _hex to _hex div 16
set _major2 to _hex mod 16 as string
set _hex to _hex div 16
set _major to (_major2 & _major1 as string) as integer
-- Concatenate the version string
set _versionString to (_major as string) & "." & (_minor as string) & "." & (_revision as string)
end try
return {__major:_major, __minor:_minor, __revision:_revision, __string:_versionString}
end systemVersion