Application

Overview

An object always available named 'application' that allows control over multiple window contexts and the ability to listen or respond to OS events. You can use the application object to change its icon, name or request attention from the user. Important: The Application object is created automatically.

Ancestors

  1. None
 

Descendants

  1. None
 

See Also

  1. process

Members

exitAfterWindowsClose
Description

Gets or sets if the application should quit (or exit returning 0) when the last remaining window is closed (Note: hidden windows still count as open windows and will prevent applications from closing). The default for this is true.

Definition

boolean application.exitAfterWindowsClose (default true)
icon
Description

The icon property allows you to set or get the current image associated with the application (and subsequently used in the dock/task bar or on window decorations). The string must be a valid URL or path to an image on the file system or application resource (For best results use 512x512 PNG image).

Definition

string application.icon
name
Description

The name property is used to get or set the process name in the task manager, or when the application is shown. Note that the packaged application name should match this name.

Definition

string application.name
packaged
Description

Gets a true or false boolean value if the application is packaged or is being ran as a script.

Definition

boolean application.packaged
visible
Description

Gets or sets the visibility of the application. This will reveal or hide all windows associated with the application. Note that other OS/UI elements may not be hidden, such as modal dialogs, or indicator icons in the taskbar.

Definition

boolean application.visible

Methods

addEventListener(eventName, callback)
Description

Adds an event listener for various application level events. The first parameter is the name of the event, the second parameter is the function to call when the event happens (e.g., a callback).

Definition

application.addEventListener(eventName, callback)
Parameters
NameTypeDescription
eventName string The name of the application event to start listening to.
callback function The function that will be called when it occurs.
attention(critical)
Description

Animates the icon in the dock or task bar to "bounce" (on OSX) or "highlight" (in Windows). If false (or nothing) is passed into this the animation is played for a short time (depending on OS preferences), if true is passed in (e.g., a critical alert is needed) the icon continues to animate until a window or the application icon in the dock is clicked.

Definition

application.attention(critical)
Parameters
NameTypeDescription
critical boolean
Returns
TypeDescription
Object An object with one function "cancel" allowing you to cancel the request.
copy()
Description

Invokes a copy operation, this takes whatever is currently selected in the focused window and control and places it into the clipboard.

Definition

application.copy()
cut()
Description

Invokes a cut operation, this takes whatever is currently selected in the focused window and control and places it into the clipboard and removes the selected element from the application (usually text or images)

Definition

application.cut()
delete()
Description

Deletes the currently selected value for the currently focused window and control.

Definition

application.delete()
paste()
Description

Invokes a paste operation, this takes whatever is currently in the clipboard and sends a paste operation to the focused window and control.

Definition

application.paste()
redo()
Description

This repeats the last rewound value of the currently focused window and control.

Definition

application.redo()
registerHotKey(key, modifiers, callback)
Description

The registerHotKey function attempts to assign a global hot key (or shortcut keyboard command) for the application. If a global hot key cannot be registered it assignts it as a local (application) hot key, if that is unsuccessful the successful property in the return object is set to false. Note the hot key may not be registered as a global hot key depending on security settings on Windows, or due to accessibility settings on OSX. Application entitlements or manually setting the application as an accessible or elevated privileged application will allow it to register a global hot key. To register a normal hot key, it's customary to use the Menu and MenuItem classes.

Definition

application.registerHotKey(key, modifiers, callback)

Example

require('Common');
var returnedObject = application.registerHotKey('m','ctrl',function() { 
 console.log('control m was pressed! ')
});
// note that the returned object can be used to subsequently unregister
// this hot key, e.g., returnedObject.unregister();
Parameters
NameTypeDescription
key string The character for the hot key, for example copy or ctrl+C, the character would be 'c', case does not matter.
modifiers string A comma delimited list of modifiers, options are 'alt', 'ctrl', 'cmd', or 'shift'. For example 'shift,ctrl'
callback function The function executed when the hot key or shortcut is pressed.
Returns
TypeDescription
Object An object with the properites: {global,successful,unregister}. 'global' indicates if the hot key successfully registered beyond the application context, 'successful' if the registeration was accepted by the OS, and 'unregister' is a function that can be executed to remove the hot key registration.
removeEventListener(eventName, callback)
Description

Removes an event listener for various application level events. The first parameter is the name of the event, the second parameter is the function that was originally given as the callback for addEventListener.

Definition

application.removeEventListener(eventName, callback)
Parameters
NameTypeDescription
eventName string The name of the application event to stop listening to.
callback function The function that would have been called.
resource(path)
Description

Takes a path to an application resource and returns a Buffer object. This is useful if you need to get access to packaged resources.

Definition

application.resource(path)
Parameters
NameTypeDescription
path string
Returns
TypeDescription
Buffer
selectAll()
Description

Selects all the values in the UI of the currently focused window and control.

Definition

application.selectAll()
undo()
Description

This rewinds a controls value (e.g., perhaps text in a textbox) for the currently focused window and control.

Definition

application.undo()
unregisterAllHotKeys()
Description

Removes all hot keys assigned by the application (with the exception of Menu related hot keys).

Definition

application.unregisterAllHotKeys()