Hi, @mrpasini. I have several macros that process selected text as input and fall back to the clipboard if nothing is selected. While building them, I found that reliably detecting whether text is actually selected is surprisingly tricky.
For example, the approach in your macro runs into trouble with apps like Drafts, which has a Copy command under both the File and Edit menus. Even when specifying the exact menu path (Edit > Copy), checking the menu state can still behave unpredictably in certain apps.
Here is the method I’ve found to be the most reliable across many applications:
For fun, I adapted your macro to use this approach:
Download: UPPERCASE @_jims.kmmacros (32 KB)
Macro-Notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System Information
- macOS 27.2 (26B123)
- Keyboard Maestro v11.1.1
It takes a several more actions, though you can easily strip out some of the extra features if you don't need them:
- Clipboard preservation: Restores the System Clipboard after checking for a selection and pasting the modified text.
- Pop suppression: Prevents the system alert sound when the Copy action runs with nothing selected.
- Empty-state feedback: Alerts you if no text is selected and the clipboard is empty.
