JavaScript/JXA Editing and the Atom Editor

The Script package in Atom can read in binary .scpt (extracting source code)

(http://www.uesp.net/wiki/Tes4Mod:Mod_File_Format/SCPT)

but can’t write it.

(It writes out text files with an .scpt extension – Script Editor often seems puzzled by them – reading but declining to resave/rewrite them, and is less puzzled or unprepared if they come back in with an .applescript extension)

Uh, this stopped working. Changing .currentApplication() to ("System Events") got it working again, but that it didn't work anymore is very disturbing.

That does seem strange. I have no idea. @ComplexPoint - Got any ideas?

(() => {
    'use strict';

    var app = Application.currentApplication();
        app.includeStandardAdditions = true
        app.displayAlert("atom.js");

})();

The code above is working fine here – you may have to give me more context.

Note that if you don't enclose it in a module wrapper (as below), there can be collisions arising from pollution of the global namespace, including by successive runs of your own script.

(() => {
    'use strict';

    

})();

That exact script runs fine for me in
Script Editor 2.8.1 (183.1) on macOS 10.11.4

I've used variations of that script, all in the global namespace, many many times without any issues.

In fact, here is an example from the official Apple documentation for JXA:

Scripting Additions, OS X 10.10 Release Notes

app = Application.currentApplication()
app.includeStandardAdditions = true
app.say('Hello world')
app.displayDialog('Please enter your email address', {
    withTitle: 'Email',
    defaultAnswer: 'your_email@site.com'
})

which also runs fine for me.

I think I must have been misremembering and it just never ran in Atom. it does, of course, run fine in Script Editor. In Atom:

That’s because the Atom Script package (like KM) runs Automation code through the bash osascript command.

As osascript doesn’t itself provide an Application object on which to call the display methods, you need to choose and specify one.

Thanks to your enthusiasm for Atom and instructions for getting up and running, I have been using Atom more and more lately. I just want to note a few general difficulties I am having:

  • Discovering packages — even thinking to look for some particular feature — is difficult.
  • Many packages do similar things, and it isn’t clear which ones to load to get a useful and non-conflicting set.
  • The most frustrating so far is the random assignment of keystrokes by packages. They:
    • are difficult to learn
    • difficult to discover
    • conflict with many of my existing global KM keystrokes
    • override or just don't support fundamental OS X keybindings such as End for end of page
    • conflict with fundamental Emacs-based text editing commands built into the OS X Text Editing System which I have been using for more decades than I care to admit to
  • conflict with other packages

I have been putting off spending the time to sort out all bindings and start pruning packages and customizing them until I had a good sense of which packages I want to use, but it is making me crazy. (The worst offender is ⌃B, which someone decided should insert a pair of braces, but to hundreds of thousands, if not millions, of developers — especially in Unix environments — means “back 1 character”.)

I don't even know how to find commands or their bindings (I don't think there is an apropos feature, nor a way to find out what a key is bound to and by which package.) I am hungry for suggestions about how to deal with all of this.

None of this is reason to give up Atom, but I am finding it very awkward to use and feel like I am dancing around it more than taking advantage of what it offers.

All valid points. You learn as you go.

Regarding key mappings, don’t even bother. Just use KM to map whatever keys you want.

Another good one is ⌘W which does something unfathomable instead of closing a tab. I haven’t found where this is bound.

I can‘t see myself going around binding every standard key that some package overrides, nor in many cases would I know how to find what package is binding the key so that I can bind something else to it. I must be missing something about using Atom. Then again, I don’t think I’ve read any of the documentation.

Atom > Preferences > Packages > [particular package] > Settings > Keybindings

@ComplexPoint -

The problem is, overriding those key bindings doesn't always work.

It's not like that. You just start using the editor. When a key doesn't do what you want it to, you redefine it in KM. It's no different than redefining it in Atom's preferences, other than that you can be sure it will work.

Do whatever you want. If you get lucky, you may have no issues with Atom's key bindings. But that wasn't my experience. When I quit messing around with them and used KM instead, I wondered why I wasted so much time doing something else.

Even when you uncheck the Enable button (as in the image above) ?

Well, that would mean having to define all the bindings I actually like.

I don’t see the issue with using KM to redefine keys. We’re intimately familiar with KM’s workings, so it’s a no-brainer as far as I’m concerned.

But whatever floats your boat. :slight_smile:

I use KM too – seems to work well – I read you to mean that using KM to override Atom bindings didn’t always work.

Ph, sorry. KM always works. :slight_smile:

That’s if you know the package. How do I find what package is binding a key? Something in my setup is binding ⌘W to do something that is apparently worthless and certainly not what I want. It splits the editor and shows this on the right:

I found where to see all the keybindings: Preferences > Keybindings!. I missed using this in the first place because I had looked at it before loading any packages, and I made the assumption that package keybindings wouldn't show here. Not only do they show, but the package is shown along with the keybinding. Here’s ⌘W:

Even better: there is a package keybinding-resolver.