This is done via the AppleEvent messaging system, a part of the Macintosh's Open Scripting Architecture.
The language was first released in 2001, and was bundled with Late Night Software's flagship product, Script Debugger.
JavaScript OSA was eventually discontinued due to lack of interest[1] and was dropped from Script Debugger 5 in 2012.
[2] OS X Yosemite introduced JavaScript for Automation (JXA): system-wide support for scripting with JavaScript, built upon JavaScriptCore and the Open Scripting Architecture.
[3] It features an Objective-C bridge which enables entire Cocoa applications to be programmed in JavaScript.