New Text Expansion From Selection [using KM8 features]

I am getting a "Invalid XML from Applescript" error on new expansions. Is this a known issue with a known fix?

Don’t know at the moment. Smells like a compatibility issue KM/OS that can be resolved with minor tweaks. I will look into it when I find the time.

Thanks for the note.

1 Like

Much appreciated :slight_smile:

I am sort of moving away from Typinator in order to stick only to Keyboard Maestro and this macro is very useful.

It worked for a while and then it stoped. Now I can't get it to work again.

In the times when I wrote this macro I was trying to do the same :slight_smile:

But it turned out that it somehow didn’t work out. Currently I’m using LaunchBar’s Snippets – via single modifier tap – to insert all my abbreviations; it is as fast as typing a fixed trigger (like with Typinator or KM), and more comfortable, because LB remembers your habitudes. For me.

Aha! Thanks for sharing :slight_smile:
Out of curiosity, why did you decided to move away from typinator? For me it was the fact that it lags for too long when I am adding new snippets or editing them.

I will definitively look into LaunchBar! I didn't pay much attention to it yet, seeing that I use Alfred quite a bit.

I have no issues with Typinator, no lags so far. I just wanted to “streamline” (thin out) my usage of background helper apps (LaunchBar, Typinator, KM Engine). So, I found out that – for me – LB’s Snippets are more comfortable than Typinator’s (or KM’s) typed string triggers. If done via single modifier tap (this is important).


Single modifier taps in the LB preferences:

My CapsLock works as Ctrl (via System Preferences), so it’s a very easy key for the left pinky, to get a snippet/abbreviation.

2 Likes

It’s running fine here, with KM 8.2.4 and macOS 10.14.6.

Which KM/OS version are you using?

Shortly I will upgrade to KM9. I’ll report back if I have any issues there.


PS:

Upgraded to KM9 now, and the macro still runs fine here.

That is odd. I am on KM9 OS 10.45.5.

Question: does it have to be on the Global Macro Group for it to work? It just installed it again and it worked fined. So I moved it to another folder and then error happened again.

No. I tested it in the Global group and in a dedicated “Text Expansions” group, both fine.

Fixed. :upside_down_face:

I use brackets on some folders name (as in [002] Text expansions) so I believe this was causing the error. I removed it and now it works again.

Thank you for your patience and willingness to help out! :slight_smile:

Weird. I tested it in a group “[002] Text expansions” and I don’t get any errors there either.

And, as far as I can see, the group name is not even used in the macro. (The group is set via %ExecutingMacroGroupUUID%)

I switched back the group name and it kept on working. Weird indeed. :face_with_monocle:

Thanks for sharing this!

Can you please share how to automatically open the newly created macro in Keyboard Maestro?

If with “open” you mean ‘open for editing’: You have to open it yourself in KM Editor. The macro is created in the same folder (group) as the creator macro.

If you mean ‘run’: Just run the macro via the typed string trigger you have set for it.

If it doesn’t create a macro, make sure it is in a group that is activated for the app you’re in.

Hi @Tom - I'm essentially looking for a macro that opens the most recently created macro in Keyboard Maestro.

In other words, when I trigger this macro, it should launch Keyboard Maestro and go to the newest created macro (in this case, the text expansion word).

Any thoughts on how to do that? Thanks

I don’t know how to open the latest created macro in general, but in this case I would try this:

In the second to last action of the creator macro you see the variable nteMacroID, which contains the later ID of the macro to be created.

Now, when I look at KM’s AppleScript dictionary I see an editMacro command that seems to take a macro ID as argument:

So, you could simply append an AppleScript action that uses this to open the created macro. (Or append the command directly to the existing AppleScript, inside the KM tell block.)
Maybe with a short delay before.

If you don’t want to open each and every created macro, then you can wrap the action in a condition, for example if Option key is down, etc.

Thanks for pointing me in the right direction!

I tried placing this code inside the KM tell block of the existing Applescript (see below). Unfortunately nothing occurs even when replacing nteMacroID with macro id macroID or macroID.

tell application "Keyboard Maestro"
	tell macro group id groupID
		make new macro with properties {id:macroID, name:macroName}
	end tell
	tell macro id macroID
		make new action with properties {xml:theAction}
		make new trigger with properties {xml:theTrigger}
		
	end tell
delay 5
	
editMacro nteMacroID

end tell

Yes, inside the AppleScript the KM variable nteMacroID is picked up by the variable macroID. (See the tell application "Keyboard Maestro Engine" block towards the beginning of the script.)

I don’t know why it doesn’t work for you. (You said you tested it with macroID too.)

This works for me:

tell application "Keyboard Maestro"
  tell macro group id groupID
    make new macro with properties {id:macroID, name:macroName}
  end tell
  tell macro id macroID
    make new action with properties {xml:theAction}
    make new trigger with properties {xml:theTrigger}
  end tell
  --delay 1
  editMacro macroID
  activate
end tell

The only additions are the 3 lines before the last end tell.

  • For me it works without delay, but this might be different with your setup.
  • The activate brings KM to the front (or launches it).

If it still doesn’t work, check the Engine.log in ~/Library/Logs/Keyboard Maestro/.

1 Like

That worked perfectly! Thanks so much!!

Glad that it works :slight_smile:

May I ask what is the purpose of opening/editing every macro immediately after creation?

I’m asking because, if it is for example a specific setting/option you are missing in the prompt window, then it would probably be easier to add that option to the prompt, instead of setting it afterwards in the created macro each time.