Yosemite: JavaScript for Automation

Yosemite: JavaScript for Automation

The Open Scripting Architecture for OS X has been around for a long time and has provided a standard and extensible mechanism for scripting applications and services on OS X.
AppleScript has been the staple OSA language for years but with Yosemite, Apple have added JavaScript.
JavaScript can be used in the Script Editor; there is a Run JavaScript automator action and you can also access it via the Terminal
Apple has got some great documentation, which is available here.
So, for example, take this simple piece of AppleScript that composes a new email along with a subject and message:

tell application "Mail"
set myMessage to make new outgoing message with properties
{visible:true, subject:"My Test Email", content:"Hello World"}
end tell


The javascript equivalent would be:

Mail = Application('Mail');
content = "Hello World";
msg = Mail.OutgoingMessage({
subject: "My Test Email",
content: content,
visible: true
});
Mail.outgoingMessages.push(msg);
Mail.activate();

So, if you have JavaScript skills, you can start using them to automate the Mac.
If you are not sure what properties are available for an app, its dictionary through script editor now lists the properties by AppleScript or JavaScript.
javascript-script-editor
Apple has even added an Objective-C bridge, allowing JavaScript to access Objective-C frameworks.
This really opens up a new chapter in OS X Automation.
Enjoy