Jump to content

Learning Alfred-run javascript via Breakpoints?


Recommended Posts

I usually learn best when I can get code into a debugger and breakpoint my way through the code. I do this with Ruby and Lua plugins by using remote debugging. The docs for Ruby are here: https://github.com/ruby/debug#remote-debugging and the Lua tool here: https://github.com/pkulchenko/MobDebug — remote debugging allows you to "hook in" to any code run by a different app (i.e. Alfred could run ruby without any explicit debug command in place, but with a breakpoint command a remote debugger could hook in to that script).

 

It seems Javascript (JXA) is a useful language for macOS automation. I see @vitor for example uses it for his great ChatGPT workflow. So my question is: is there a remote debugging interface that would enable me to run an Alfred workflow, and breakpoint a Javascript script and inspect it as it runs?

Edited by iandol
Link to comment
Posted (edited)

To answer my own question (after trying to do this in VSCode, so many JS tools its hard to find what you want...)

 

Open Safari, enable developer tools then enable this option:

 

image.thumb.png.89d2ceb7873cfe8310d0344a13bf8401.png

 

Now in your JXA script type in

debugger;

where you want, e.g. 

 

image.png.37881dc11bd32c9dd1b48387706d7297.png

 

Now use Alfred as you normally would and when Alfred runs the script, the remote javascript debugger will pop up. Cool!

 

 

Edited by iandol
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...