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 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, returnsundefined
if the app is not currently runninglaunch(String appName, Map<String, AnyObject> optionals)
launches and returns the app with the given name, returnsundefined
if unsuccessfulfocused()
returns the focused appall()
returns all running apps
Launch Optionals
focus
(boolean): if settrue
the 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-1
if 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()
returnstrue
if the app is currently frontmostisHidden()
returnstrue
if the app is hiddenisTerminated()
returnstrue
if the app has been terminatedmainWindow()
returns the main window for the app, returnsundefined
if 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, returnstrue
if successfulfocus()
activates the app and brings its windows to focus, returnstrue
if successfulshow()
shows the app, returnstrue
if successfulhide()
hides the app, returnstrue
if successfulterminate(Map<String, AnyObject> optionals)
terminates the app, returnstrue
if successful
Window Optionals
visible
(boolean): if settrue
returns all visible windows for the app, if setfalse
returns all hidden windows for the app
Terminate Optionals
force
(boolean): if settrue
force 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');