Recently I considered the above question. To me it is important to know which tool to select to execute the job at hand.
P.S. I realize that you can run JXA/Applescript in Keyboard maestro, so technically everything is easy to do in Keyboard maestro, but that I feel is dodging the question. If someone wants to know ‘what they can get away with’, knowing what the requirements are is important.
P.S.S Also not here that I’m not asking “Which is better” because that is entirely subjective.
I came up with the below list:
What can you do with Keyboard Maestro that you can’t do (easily) with JXA/AppleScript:
Global Keyboard Shortcuts
Fuzzy Picture Search
What can you do with JXA/AppleScript that you can’t do (easily) with Keyboard Maestro
I like to think of KM as a library of macros/scripts that easily searchable and easily extendable.
KM provides a rich set of primitive building blocks to create complex or simple on-off scripts that do a job you need. In that way KM can act as a storage for all your JXA/Applescripts, at least it I look at KM in this way.
But you can also consider the speed with which you can iterate on KM. I myself really enjoy the ‘visual programming’ that KM brings to the table. It’s so fun and easy to stack macros on top of each other and see how they can interact to complete a job. And with @DanThomas’s extensions he brought to KM, KM for me is a full fledged automation IDE.
Although I hope @peternlewis can bring these features to KM natively as the speed of these extensions Dan built is still not as great.
At the end of the day, both JXA and KM and Applescript are tools that help you achieve a task, use what you think is best or what you know is best.
I view KM and scripting as complementary tools. Which tool is easiest to use for any specific job depends on the job and the user.
Another way to look at it is that the KM Execute an Script actions (KM Wiki) are a way to easily extend the bulit-in, native features of KM.
Having said that, here are some thoughts off the top of my head.
2017-09-05 20:47 CT
Things Better Done in Scripts
Array and Record Handling
KM can't really do this, at least not as well as AppleScript. All KM Variables are text, with some limited support for pseudo numeric arrays, using CSV.
KM recently added support for pseudo text arrays.
Complex navigation of the UI
Like finding, selecting, setting, UI Elements buried in a window.
Scripts can't do this at all without some 3rd party image tools
Basic UI Control -- very easy in KM
Select and/or Show Menu Items
Get Status of Menu Items, Buttons, Checkboxes
Extensive Window management/manipulation
Extensive use of Mouse (not available at all in AppleScript)
Some of this stuff can be done in AppleScript and Shell Scripts, but, for the most part, it is far easier to do in KM.
Date Handling/Formatting
I'm sure there are more. I'll update when/if I think of them.
So, if you have skills in KM and scripting, then you will generally know which is the best tool for the job. If you're not sure, you can always post in this KM forum to get advice/suggestions.
I have three tools I consider essential to my Mac automation work:
The above can be done locally I believe (handling key events). I think you would have to assign the "keyDown" event to the AppDelegate. The "performKeyEquivalent" event may work also here. Note I haven't ever tried this.. But you are correct in saying that Global Keyboard shortcuts are probably impossible without 3rd party tools.
Well they are Objective C commands. So would use AS/JXA-ObjC bridge. If possible to send a block over to ObjC using the bridge at least. I’m not sure how that works, if at all.