Find out the current platform and system version

This lesson demonstrates how to find out the current operating system and platform. This can be useful if your application has minimum system requirements.

The isOSX function

The isOSX function returns true if the current system is an OSX system and false if not.  The function takes no parameters and is called with a statement such as the following:

if isOSX() then makeExtraTabRoom
if the platform is "MacOS" and isOSX() then showAqua

The platform function

You find out the current operating system by using the platform function. The platform returns "MacOS" for both Mac OS and OS X systems, so a little additional code is needed if you need to distinguish between the two.  On Windows the function will return "Win32", on Linux "Linux" and on Unix platforms the currently running variant.

if the platform is "MacOS" 

The systemVersion function

We start by getting the systemVersion. In this example we need to differentiate between "Classic" Mac OS and Mac OS X.  System versions on both Mac OS X and Mac Classic are in the form [major version].[minor version].[bugfix], with each component being a number. Mac OS X system versions start with the number 10. For example, a typical Mac Classic systemVersion is "8.6.1", while a typical Mac OS X systemVersion is "10.1.5". We can therefore test the first component of the systemVersion to find out whether this is an Mac OS X system.

To do this, we use a chunk expression. Items in a chunk are normally delimited by a comma, but the itemDelimiter property can be used to change this to any character. Since the components in the system version are separated by periods, the function sets the itemDelimiter to a period. Once this is done, the expression item 1 of the systemVersion reports the first component of the system version. If we're on a Mac and the first component is 10 or greater, this system is Mac OS X and the function returns true; otherwise, the function returns false.

set the itemDelimiter to "."
if 1 of the systemVersion >= 10

The isOSX function code

function isOSX
	## Mac OS system versions are of the form "x.y.z"
	## OS X system versions are "10.x.x"
	set the itemDelimiter to "."
	if the platform is "MacOS" and item 1 of the systemVersion >= 10 then
		return true
		return false
	end if
end isOSX


Add your comment

E-Mail me when someone replies to this comment