Is it possible to run JXA in another editor

I recently got into automation with javascript for OS X and I am curious whether I can run this javascript from command line. I just want to use a different code editor for writing and running JXA and really curious if I could use it in 'Coderunner' or Sublime text editor and run it from there. I would assume that I could just run it with Node.js but that does not work for some reason. :frowning:

Also I am really wondering what is the real difference between using JXA and Applescript for writing out os x automated scripts. I am learning javascript for web development now so I was thinking of just using JXA for everything and not bother learning and using Applescript although it does look quite nice. Can I do everything in Applescript that I can do in JXA?

I think so, although I have NOT done so myself. See:
JXASublimeText
Run and Build JavaScript for Automation Scripts and Applets

In theory, according to Apple, you can use either language as the interface to Apple Events.
So they should be equivalent.

In practice, there have been a few things that AppleScript could do, that JXA could not do.

For more info, see:
JXA OS X 10.10 Release Notes

Open Scripting Architecture (OSA) Component
The JavaScript OSA component implements JavaScript for Automation. The component can be used from Script Editor, the system-wide Script menu, the Run JavaScript Automator action, applets, droplets, the osascript command-line tool, the NSUserScriptTask API, and everywhere else that other OSA components, such as AppleScript, can be used. This includes Mail rules, Folder Actions, Address Book plug-ins, Calendar alarms, and message triggers.

You may also find this video helpful:
2014 WWDC session video on JXA

I think that makes good sense. If you don't already know AppleScript, then I don't see the need to learn it for the very few times it might be required. When/IF those times happen, you will probably be able to get someone to help you translate the part of JXA to AppleScript.

Keep in mind that JXA can use AppleScript Script Libraries, but NOT the other way around.

To make JXA development easier, you need to be running El Capitan so you can use the Safari JavaScript debugger with JXA.

I don't have much experience here, but you should be able to run JXA from shell scripts just like you do AppleScript. Here's a simple example:

osascript -l JavaScript -e 'Application("iTunes").currentTrack.name()'

For more info, do an Internet search on "jxa osascript"

1 Like

The main limitation of other editors is that the JSContexts mechanism for using the Safari (Webkit) debugger with JavaScript for Automation is limited to Script Editor.

(You can, however, debug other JavaScript contexts, like TaskPaper script evaluation, and you can always paste into Script Editor when you need the debugger).

Atom is probably most actively supported editor at the moment:

Here it is editing and running a compiled JavaScript for Automation .scpt file:

The Atom packages to pull in are:

That video shows (near the end) how you can make a service that evaluates the JavaScript in whatever editor you were working in e.g. TextEdit.