System

Technology area
Installer

Overview

The System object provides access to information about the target host. This object is accessed using the system global variable.

Tasks

Properties

Accessing Object Properties

Accessing System Information

Comparing Version Numbers

Internationalizing Distributions

Logging

Running Programs

Properties

applications

Discussion

Provides methods to obtain information about running applications. See Applications.

defaults

Discussion

Dictionary representing the defaults system.

files

Discussion

Provides file-access methods. See Files.

ioregistry

Discussion

Provides access to the IOKit registry. See IORegistry.

users.desktopSessionCount

Discussion

Number of logged-in users. (Includes only those users with a Window Server connection, that is, those that appear in the Fast User Switching list.)

version

Discussion

Dictionary (associative array) with the contents of /Sytstem/Library/CoreServices/SystemVersion.plist. See sw_vers.

Methods

compareVersions

Provides the result of comparing two given version strings (for example, '10.3.1' and '10.4').

compareVersions( versionA, versionB)
Parameters
versionA

String with the first operand version.

versionB

String with the second operand version.

Return Value

-1 when versionA is lower than versionB, 0 when versionA is equal to versionB, and 1 when versionA is higher than versionB.

gestalt

Provides gestalt information that corresponds to the given selector.

gestalt( selector)
Parameters
selector

String specifying the selector for the data to retrieve.

Return Value

Data for the given selector.

Discussion

For example, this expression returns '1040' on OS X v10.4.0:

system.gestalt('sysv').toString(16)

See Gestalt Manager Reference for detailed information.

localizedStandardString

Provides the localized standard string in the installation package for the current locale for a given key.

localizedStandardString( stringKey)
Parameters
stringKey

String that identifies the desired localized string.

Return Value

Localized string, if found in the installation package; null otherwise.

localizedStandardStringWithFormat

Provides the formatted localized string in the installation package for the current locale for a given key and a given set of additional arguments.

localizedStandardStringWithFormat( stringKey, args...)
Parameters
stringKey

String that identifies the desired localized string.

args...

Arguments that replace placeholders (%@) in the formatted localized string.

Return Value

Localized string, if found in the installation package; null otherwise.

localizedString

Provides the localized string in the installation package for the current locale for a given key.

localizedString( stringKey)
Parameters
stringKey

String that identifies the desired localized string.

Return Value

Localized string, if found in the installation package; null otherwise.

localizedStringWithFormat

Provides the formatted localized string in the installation package for the current locale for a given key and a given set of additional arguments.

localizedStringWithFormat( stringKey, args...)
Parameters
stringKey

String that identifies the desired localized string.

args...

Arguments that replace placeholders (%@) in the formatted localized string.

Return Value

Localized string, if found in the installation package; null otherwise.

log

Generates an Installer log entry with the JS: prefix.

log( logString)
Parameters
logString

Log-entry text.

Discussion

For some objects, this function may print data that is unavailable or formatted differently when accessed in JavaScript code. To ensure that only data accessible in JavaScript code is shown in the log entry, invoke this function this way:

system.log(foo + ' ')

Such invocation forces the JavaScript interpreter to evaluate the expression and pass a String object to the function.

propertiesOf

Provides an array with the properties of a given object.

propertiesOf( object)
Parameters
object

An object.

Return Value

Array with the properties of object.

run

Launches a given program in the Resources directory of the installation package.

run( programName, args...)
Parameters
programName

Name of the program to execute.

args...

Arguments passed to the program.

Return Value

After the program is executed, its exit code. If the program is not executed (see discussion), undefined.

Discussion

The allow-external-scripts attribute of the options element in the distribution definition must be 'yes' for the program to be launched. And, the Installer application asks the user’s permission before launching the program. See Distribution Definition XML Schema Reference for more information.

See Also

runOnce

Launches a given program in the Resources directory of the installation package. On subsequent invocations with the same arguments, the program is not launched and the exit code of the first execution is returned.

run( programName, args...)
Parameters
programName

Name of the program to execute.

args...

Arguments passed to the program.

Return Value

After the program is executed, its exit code. If the program is not executed (see discussion), undefined.

Discussion

The allow-external-scripts attribute of the options element in the distribution definition must be 'yes' for the program to be launched. And, the Installer application asks the user’s permission before launching the program. See Distribution Definition XML Schema Reference for more information.

Use this method instead of run when a program’s exit code using the same arguments is not expected to change.

sysctl

Provides the result of a sysctlbyname() call using the given selector.

sysctl( selector)
Parameters
selector

String with the hardware selector for the desired data.

Return Value

Hardware data corresponding to selector.

Discussion

See /usr/include/sys/sysctl.h for the list of hardware selectors.