Uh, this stopped working. Changing .currentApplication()
to ("System Events")
got it working again, but that it didn't work anymore is very disturbing.
(() => {
'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
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.
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.
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.