3

The AppleScript way to launch a Mac application is:

tell application "iTunes"
  activate
end tell

What's the equivalent in JavaScript for Automation (JXA)?

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96

1 Answers1

4

Launching an application via Mac's JavaScript for Automation is done like this:

var itunes = Application('iTunes');
itunes.activate();

The Application call looks inside the /Applications directory. Any app there can be called by name.

The .activate() call starts the app and makes it the front window. If it's already running, the application is simply moved to the front window.

It appears the UI switch can take a little time. Use something like:

delay(0.3);

to create a brief pause (three tenths of a second in this case) to let the UI catch up before continuing to send scripted commands to the app.

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96