MACRO(s): Debug JXA from Atom, Finish Debugging JXA from Atom
These are helper macros to make it easier to debug JavaScript for Automation (JXA) scripts when using Atom. You may decide to edit them to change the workflow, but they work (on my machine) as is.
###Assumptions:
- You already know how to use Atom for JXA editing. If you don't, I'll (hopefully) be documenting this in a post or wiki entry in the near future.
- You already set up Safari for debugging (i.e. you have the "Develop" menu available in Safari, and have "checked" the appropriate submenu item(s) for your computer).
These macros are extremely easy to use.
##Debug JXA from Atom
Debug JXA from Atom.kmmacros (14.2 KB)
###Workflow:
- Situation:
- You've got a JXA script you're editing in Atom, and it already has a file name so "Save" will work without requiring user intervention. NOTE: Saving isn't strictly necessary so if you want to eliminate that step, go ahead).
- Script Editor is NOT running.
- Run this macro.
- It starts Script Editor and has it compile and run the script. Opens Safari if needed.
- If a "debugger" statement is encountered, or Safari is set up to pause when encountering a JSContext, it will show the debugger.
###Detailed Steps:
- You launch this macro.
- The Atom script is copied to the clipboard, and the file is saved.
- If Script Editor is open, the macro is canceled with an error, so we don't accidentally overwrite an unsaved script.
- Script Editor is launched.
- SE starts a new document, for JavaScript.
- The text copied from Atom is pasted in.
- If Safari is not running, it is started, and the "Develop" menu is opened then closed (doesn't seem to work without this step, on my machine).
- Back to Script Editor, which compiles the script.
- If compile errors, they are displayed and the macro cancels. Everything is easier if you eliminate compile errors before triggering this macro.
- SE runs the script.
- Assuming a "debugger" statement is hit, or Safari is set up to pause right away when it sees a JSContext, Safari will open the debugger window.
Finish Debugging JXA from Atom
Finish Debugging JXA from Atom.kmmacros (6.5 KB)
Trigger this macro while in the Safari Debugger. It closes the Debugger window, closes Script Editor without saving, and returns to Atom.
I have these 2 macros set to the same hotkey trigger. In Atom, I press F15 to debug. In Safari, I press F15 to quit debugging.