Debugging JXA with Automator

Hey @DanThomas, @ComplexPoint, and @ccstone, and any other interested parties:

For the longest time we have thought, or at least I have thought, that you could only debug JXA scripts in Safari from the Script Editor. Well, maybe it can be done from Automator as well.

I just had the occasion to reread the Apple Yosemite Release Notes again, and I was surprised to find this:

JavaScript for Automation now allows you to ==debug scripts with Safari's Web Inspector==. This feature can be used by scripts run in Script Editor and ==by the Run JavaScript action in Automator.==

Have any of you guys tried this?

In the Apple WWDC 2014 JXA session, Josh shows an Automator workflow that will run the JXA script in the frontmost app -- any app. He showed it in TextEdit but said it would work in any app.

I've been looking for that Automator workflow, but have not found it so far.
This would be great! You save the Automator workflow as a service, assign a shortcut key to it, and then when you are in your favorite editor with a JXA script, just press the shortcut key.

This opens up a lot of opportunities, if we can make it work.

Your thoughts?

1 Like

Hey guys, maybe one of you JXA gurus can figure out what the code should be from this screen shot of Automater:


The Automator script gets the entire text of the frontmost document, and then evaluates it as a JavaScript.