Automator should be a last resort at the moment if you want to future proof your work. Sometimes it is still the best option, but Apple are putting their automation focus on Shortcuts for several years now and at some point Automator may be deprecated. Shortcuts carries forwards a lot of inspiration from Automator, so you should find the approach familiar assuming you haven’t touched Shortcuts before.
That being said I did start by looking to see what could be done with Automator anyway,
The first thing I tried was experimenting with the Workflow Receives setting and the Output replaces selected text on the Automator Quick Action settings.
Setting the receives to “no input” along with the enabled output dropped the Quick Action from the services menu. Presumably it is an invalid combo as far as Automator is concerned. Changing it to text like this works (with a simple awk
instruction to reverse and output the text on the clipboard (supplied via the use of pbpaste
(the clipboard on macOS is technically the pasteboard, hence the pb
prefix)).
However, this then only shows up when there is selected text. So that would b great if you wanted to transform selected text rather than your clipboard (in which case you could use this approach and use Automator to get the text selection and forego the clipboard). Assuming you are not replacing text, then that’s a no go.
Although you could trigger via keyboard shortcut which might work around that - you could try it via the Keyboard Settings on your Mac.
The next thing I considered was to use some AppleScript to paste the result after placing the script output on the clipboard.
tell application "System Events" to keystroke "v" using command down
This actually gave me an error telling me the Automator helper was not permitted to send application keystrokes. I tried a similar approach in Shortcuts and it gave the same error but for the Shortcuts helper. This is interesting to note from a security perspective, but fortunately Shortcuts has a better option anyway, which does work.
You can set a Shortcuts shortcut as a Quick Action and you can also set it to output, just like Automator, but here the options to include in the Services menu and not require text selection to output are more forgiving.
Here’s an example shortcut using the same script as before, and you can download it with the link below.
https://www.icloud.com/shortcuts/b602abfb87aa40ac865db15036deacd3
pbpaste
gets the clipboard content and as in Automator, I can just pipe that straight into awk
. I think that’s the most efficient approach for you at this point rather than dealing with Shortcuts’ variables, though that is also an option. I think in this case I’d probably just script it like this anyway and have it contained rather than adding in more “colour” from Shortcuts.
I did actually try piping this into pbcopy
in the script to put the content on the clipboard, but there seemed to be a timing issue and it didn’t work reliably for me. Instead, what I did was simplify things to just have Shortcuts output the shell result (to wherever the cursor is). This leaves the clipboard intact, which may or may not be desirable. It depends what you want to do with the clipboard next, if anything. If you do want the clipboard modified, you can insert a Copy to Clipboard action after the script step and it will copy to the clipboard just before outputting at the cursor, and that seemed to work reliably when I gave it some quick tests.
Hope that helps lay things out a little, and I am sure there are more ways and tweaks that could be applied. There may even be a better way to do it with Automator than what I tried. I must admit I create new Automator workflows so infrequently since Shortcuts came to the Mac that it’s getting fuzzy now; but hence I’d come back to recommending Shortcuts over Automator … though as you’ll derive from a number of conversations on the forum, Shortcuts does have its issues, so Automator’s stability and maturity do have that still going for it.