Here is a macro for creating a new text expansion macro from the selected text. Select the desired text, trigger the macro (by default it is with a Status Menu trigger, adjust as desired), enter the trigger text when prompted and the macro will be created.
Updated using version 8.x AppleScript facilities.
Note that although it attempts to encode the HTML entities, the requirement is that it actually be XML entities, and so it will not necessarily work well for non-ASCII text.
I imported your macro and then moved it to a different macro group expecting the new text expansion macro to be placed in that same macro group, but it appeared in the “Text Expansions” macro group (even though I deleted this macro group after moving your macro; KM recreated the macro group). How does KM decide where to put the new text expansion macro and can it be changed?
It works fine for me on Mojave with the latest KM and PopClip. But, you have to make sure KM and PopClip have complete access to other applications in the Security & Privacy → Privacy section. The os should of ask for permission the first time you ran it on Mojave, but if you missed it and accidentally told it no (I did the first time), then you have to manually add the permissions.
Hi Peter, this is such a great macro. Unfortunately for me it seems to fail when the selected text is in Microsoft Word and includes the "–" dash that replaces a "-" when typing. I tried first using Remove Styles on the Text variable to no avail. E.g.,
Here's some text – and some text following the dash.
Presumably the XML does not accept the HTML entities, such as –. Keyboard Maestro does not have a filter that only produces numeric entities, so you will just have to do that yourself for any entities you encounter, add a Search & Replace the Text Variable, – for –
So glad I found this extremely useful macro! I started with Peter’s since it is newer but had to revert to reboot81’s “ByPasting” version. Not sure if anybody else had issues, but I was getting some“misfires” because of the typing and interference with other Keyboard Maestro macros/Typinator snippets. Example: a long url with the word english (lowercase) in it was rendered EEnglish because I have a snippet that autocapitalizes english→English and I guess because of the typing speed, it got confused and the url broke. Don’t know if others had similar issues with “by typing”. Anyway, it might be nice if Peter’s could be modified to include a “ByPasting” option to avoid this kind of issue.
To really know, you'd just have to change one of the created actions to By Pasting and then copy the XML for the action, and then take a look, but they are usually (tho not quite always) obvious - occasionally the internal terminology is not the same as the visible terminology.