What can you do with Keyboard Maestro that you can't do (easily) with JXA/AppleScript and visa versa (KM vs Scripting)

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

  • Compile to a .app file

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. :slight_smile:

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
  • Complex formulas
  • Complex string handling (except for RegEx)
  • Complex clipboard manipulations

Things Better Done in KM
(some things can be done only in KM)

  • RegEx
    • AppleScript does not have any native RegEx support. Requires use of Satimage.osax or more complex ASObjC.
    • JXA has a great RegEx engine, but the visual RegEx setup in KM is excellent
  • Assigning of shortcuts (hotkeys) to Macros (set of Actions)
    • Scripts can't do this. Requires 3rd party tools like FastScripts
  • Processing of Files/Folders in Finder Selection
    • While this can be done in scripts, KM makes it very easy for everyone
  • Actions based on image recognition
    (like Move or Click Mouse action (KM Wiki), based on Found Image)
    • 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. :wink:

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:

  • AppleScript and JXA
  • KM
  • RegEx
4 Likes

Nice list!

Worth noting:

Assigning of shortcuts (hotkeys) to actions

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.

Edit: Just found a page about local and global event monitoring. It looks like it may be possible in JXA/AS using addGlobalMonitorForEvents and addLocalMonitorForEventsMatchingMask. Untested of course

Since those are not native AppleScript commands, how would you implement in AppleScript?

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.

Just updated my thoughts on KM vs Scripting.