JXA-Cookbook / JXA-Cookbook

Cookbook for JavaScript for Automation in Mac OS X Yosemite
2.88k stars 116 forks source link

Using Javascript in OS X Script Editor #6

Closed RobTrew closed 5 years ago

RobTrew commented 9 years ago

Perhaps this is tangential to JXA, but do we know the format / API for Yosemite Script Editor plug-ins ?

( as in Script Editor > Preferences > Plugins )

( Raw Script Editor has quite limited built-in support for JXA – no automatic reformatting, indenting, quoting – and filling these gaps with scripts yields slowish performance ... )

I haven't seen any documentation for these plug-ins ...

dylan-chong commented 8 years ago

I know this doesn't answer the question, but if you hate the script editor, you can save the script as a text file and then edit the file in vim or whatever. You can then call the script with osa -l JavaScript path/to/the/script, or better yet, setting up gulp watch to auto-run your script. That's what I did just recently (checkout my repo to 67ae47605b4163b82f980cf6d0bdc9266db9b57a).

RobTrew commented 8 years ago

Yes, I do think an alternative editor works better. I now use two packages in Atom, which enables me to run JavaScript for Automation code in the editor and see the output in an Atom panel (by tapping ⌘I).

The only limitation of alternative editors is that using the Safari debugger with JXA is only enabled for the Script Editor.app context, so for debugging you may need to switch back into it.

To add things like comment-toggling, block indent/outdent etc, (for the times when you do need Script Editor), you can put JXA macros into the SE Script Library folder, and bind keystrokes to them.

ELLIOTTCABLE commented 7 years ago

@RobTrew Er, are you sure about that? or do you mean something other than how I parsed it, or has it changed in the year since? Because I refuse to touch Script Editor, and have definitely been having osascript invocations with debugger; statements launching Safari w/ the Web Inspector!

RobTrew commented 7 years ago

That sounds good. How are you running the scripts, and what are your Safari > Developer settings ?

Are you getting a debugger activation from running a shell script like this, for example:

osascript -l JavaScript <<JXA_END 2>/dev/null
    debugger;
    Application('Finder').selection().length
JXA_END

?

JMichaelTX commented 7 years ago

Are you getting a debugger activation from running a shell script like this, for example:

Confirmed!

I did get the Safari debugger activation using your shell script, running Safari 10.1 (11603.1.30.0.34) on macOS 10.11.6