Trying to invoke a KM macro as a macOS service, bur there's a problem before I even can start that

I have one suggestion and one question. Suggestion: try adding a notification or Display Text action to the beginning of the macro to see if it’s being called by the AppleScript. Question: what are you doing with the results of the shell script in the KM action? Are you pasting them, saving them as a variable, or something else?

Yes! I did get a “beep” when I put a beep action at the top of my TestSort KM macro. Wasn’t expecting that. Now let me read your other question.

Oh sorry, I forgot to post that. Maybe there's a mistake here, but it's the same as I posted above.

Seems like we might be back to square one then, since I can’t see why that would fail to paste. But out of curiosity, what happens when you change it to “display results in a window”?

If I do that it appears to give the correct results, but only in a window:


Well, if you’re getting those results in the window, it’s proof that everything is working as intended except for the paste. From here, you could either try saving the results to the clipboard and pasting them manually, or saving them to a variable and passing them back to the AppleScript Automator action and use that as the workflow/service’s output.

Understood. I do have several Macs in my house. If they are all affected, that could imply your setup is different from mine, but if I’m the anomaly, then that implies my setup is incorrect. I may try that tomorrow. It’s quite late in this time zone. Thanks for the insightful help.

No problem. For what it’s worth, this is a new Mac acquired in October of last year, and as far as I know is running a fairly stock install of High Sierra, so I doubt there’s anything special about my setup that would allow this to work. Hopefully you’ll have more luck with one of your other Macs and can figure out what’s up with the one you’re using.

EDIT: Now that I think of it, there are more troubleshooting things you can do to figure out why the macro isn’t pasting the text as expected. For starters, I presume you don’t have a problem with the Insert Text via Pasting/Typing action not working in other macros? Well, why not try saving the shell script action’s results to a KM variable and inserting the variable by pasting? Or try a stand-alone KM macro that performs a copy operation and uses a shell script action to process the clipboard and paste the results, and see if that works when not run from an Automator workflow?

That's good. It's clearer that way.

I experience the same behavior as @Sleepy. It's not pasting for me on macOS High Sierra.

Using @gglick suggestion to save the results of shell script in a variable, it's possible to replace output in an Automator Service.

If you have a system with Sierra (onwards), you can try it.

Test (115.2 KB)

Keyboard Maestro 8.1.1 “Test” Macro

Test.kmmacros (1.5 KB)