App
Use App to control apps. Beware that an app can get stale if you keep a reference to it and it is for instance terminated while you do so, refer to isTerminated().
Interface
class App implements Identifiable
static App get(String appName)
static App launch(String appName, Map<String, AnyObject> optionals)
static void launch(String appName, Map<String, AnyObject> optionals, Function callback) // 5.0.0+
static App focused()
static Array<App> all()
int processIdentifier()
String bundleIdentifier()
String name()
Image icon()
boolean isActive()
boolean isHidden()
boolean isTerminated()
Window mainWindow()
Array<Window> windows(Map<String, AnyObject> optionals)
boolean activate()
boolean focus()
boolean show()
boolean hide()
boolean terminate(Map<String, AnyObject> optionals)
end
Static Methods
get(String appName)returns the running app with the given name, returnsundefinedif the app is not currently runninglaunch(String appName, Map<String, AnyObject> optionals)launches and returns the app with the given name, returnsundefinedif unsuccessfulfocused()returns the focused appall()returns all running apps
5.0.0+
launch(String appName, Map<String, AnyObject> optionals, Function callback)launches the app with the given name and calls the callback function if provided, the callback receives the app as the first argument orundefinedif unsuccessful
Launch Optionals
focus(boolean): if settruethe app will automatically be focused on launch, by default the app launches to the background
Instance Methods
processIdentifier()returns the process identifier (PID) for the app, returns-1if the app does not have a PIDbundleIdentifier()returns the bundle identifier for the appname()returns the name for the appicon()returns the icon for the appisActive()returnstrueif the app is currently frontmostisHidden()returnstrueif the app is hiddenisTerminated()returnstrueif the app has been terminatedmainWindow()returns the main window for the app, returnsundefinedif the app does not currently have a main windowwindows(Map<String, AnyObject> optionals)returns all windows for the app if no optionals are givenactivate()activates the app and brings its windows forward, returnstrueif successfulfocus()activates the app and brings its windows to focus, returnstrueif successfulshow()shows the app, returnstrueif successfulhide()hides the app, returnstrueif successfulterminate(Map<String, AnyObject> optionals)terminates the app, returnstrueif successful
Window Optionals
visible(boolean): if settruereturns all visible windows for the app, if setfalsereturns all hidden windows for the app
Terminate Optionals
force(boolean): if settrueforce terminates the app
Events
See Events for a list of available events for App.
Example
// Launch Safari with focus
App.launch('Safari', { focus: true });
// Get the focused app
const focused = App.focused();
// Get all windows for the focused app
const windows = focused.windows();
// Get Safari
const safari = App.get('Safari');