MacGap 2 exposes an object called MacGap inside JavaScript.

Hint: all methods and properties of the MacGap object are capitalised.

Properties

MacGap.applicationPath

Path to application.

Example usage

var appPath = MacGap.applicationPath;

MacGap.resourcePath

Path to application's resources directory.

Example usage

var resourcePath = MacGap.resourcePath;

MacGap.documentsPath

Path to the current user's documents directory.

Example usage

var documentsPath = MacGap.documentsPath;

MacGap.libraryPath

Path to the app's library directory.

Example usage

var libraryPath = MacGap.libraryPath;

MacGap.homePath

Path to the application's home directory. This is the application’s sandbox directory or the current user’s home directory (if the application is not in a sandbox).

Example usage

var homePath = MacGap.homePath;

MacGap.tempPath

Path to the App's temp directory.

Example usage

var tempPath = MacGap.tempPath;

MacGap.idleTime

Get the system idle time.

Example usage

// Get the system idle time. This example outputs the idle time to the console once per second.
window.setInterval(function(){
    console.log( MacGap.idleTime );
}, 1000);

Methods

MacGap.activate()

Activate the application (bring to front).

Example usage

MacGap.activate();

MacGap.terminate()

Quit the application.

Example usage

MacGap.terminate();

MacGap.hide()

Hide the application.

Example usage

MacGap.hide();

MacGap.unhide()

Un-hide the application.

Example usage

MacGap.unhide();

MacGap.beep()

System bell.

Example usage

MacGap.beep();

MacGap.bounce()

Bounce the Dock icon of the application.

Example usage

MacGap.bounce();

MacGap.setUserAgent(userAgent)

userAgent is a string.

Set a custom user agent string.

Example usage

MacGap.setCustomUserAgent('new user agent string');

MacGap.launch(appName)

appName is a string.

Launch the specified application.

Example usage

MacGap.launch("TextEdit");

MacGap.openURL(url)

url is a string.

Open the given URL in the default browser.

Example usage

MacGap.openURL("http://google.com");

MacGap.notify()

Notify the user by one of the following:

  • send a Native User notification
  • trigger a modal 'sheet'

User notifications by default will trigger a sound. This can be disabled by setting the sound property to false.

MacGap.notify({
    type: 'sheet', // Optional. Defaults to user notifications.
    title: 'A title',
    content: 'Some content.',
    sound: false, // Optional. Defaults to true.
});