Changing Typed String Trigger Setting for Many Macros?

Hi, I have numerous macros that consist of a typed string trigger and an insert text action. What are my options to change the trigger option "following any character" to "following a word break" in numerous macros?

Thanks,

Chris

Are they all in the same macro group? Or do their names share any sort of naming convention?

They are in different macro groups. Their names start with Text: Some are already set to a trigger with "following a word break", most are not.

Let me preface this by saying that mass modification of your macros can be dangerous. Therefore, I HIGHLY recommend making a backup of your macro library before attempting this. If you’re not sure how, do not proceed; let me know and I can give you several options.

That being said, this macro will update ALL macros whose name begins with TEXT: (or whatever you place into the variable at the beginning of the macro), by deleting their existing trigger(s), and making a new one with the “following a word break” parameter. The typed string itself will remain the same.

NOTE: If your macros have more than one trigger, this is not a proper solution as it will delete all triggers and replace them with only the typed string trigger. So if that is your case, let me know and I will see what else I can come up with.

Change typed string triggers.kmmacros (8.9 KB)

Macro screenshot (click to expand/collapse)

2 Likes

Thanks for the macro. Unfortunately, it does not work for me. After 20 seconds I get the following error. There is no other output and nothing seems changed.

2023-02-15 20:38:18 Execute an AppleScript failed with script error: text-script:283:286: execution error: „Keyboard Maestro“ hat einen Fehler erhalten: „macro "Text: [[Wiki:Diskussionsseiten]]"“ kann nicht gelesen werden. (-1728). Macro “Change typed string triggers” cancelled (while executing Get the curren trigger and determine if it is set to “following a word break” or not).

@peternlewis Making adjustments to several macros should be easier. Currently, only “Multiple Selections” is displayed when selecting several macros. At least adjusting the options of the triggers should be possible.

It's a lot more complicated than that in practice.

If you want to select multiple macros, and they have different triggers, how would you adjust the trigger options? Every option in a trigger now needs a “multiple current values” display. What if they are entirely different triggers, how would that be displayed in a way that allowed editing the different macros?

It would be pretty impractical to implement for what amounts to a very rare use case.

1 Like

How much time do you reckon it would take Peter to design, implement, and debug a UI to do all that?

100+ hours?

Do you really think that's an effective use of his time?

This can already be done with AppleScript if you want to spend the time and effort to learn how.

Could you hack "Keyboard Maestro Macros.plist" directly? Finding all

							<key>MacroTriggerType</key>
							<string>TypedString</string>
							<key>SimulateDeletes</key>

...and replacing with

							<key>MacroTriggerType</key>
							<string>TypedString</string>
							<key>OnlyAfterWordBreak</key>
							<true/>
							<key>SimulateDeletes</key>

Although that would do all typed string triggered macros rather than a subset.

Perhaps export all the macros to be changed out to a folder, do the above search and replace across all the files in that folder (BBEdit multi-file S'n'R for FTW! Or even a KM macro...), then re-import them?

But... Hang on -- It's easy enough to change one macro in the KM GUI, just annoying to do a whole bunch. Isn't that sort of repetitive problem what KM macros are for? So, a macro that uses AppleScript to get the selected macros, opens each for editing, and fires off a second macro to do the GUI stuff:

Restrict the Selected Macros.kmmacros (2.0 KB)

Image

Add Typed String Restriction.kmmacros (57.9 KB)

Image

If some of your selection will need changing and others have already been set, you can get clever and include a short timeout for the image-detecting action, with an added "Log macro name on error and then Cancel macro" routine.

3 Likes

This task gets a little bit "fun" to do with AppleScript, and I'm not going to pursue it any further at the moment – but here's a script that will find all macros with typed-string triggers. (I think. I have not thoroughly tested.)

This takes about 14 seconds to run on my old i7 MacBook Air with macOS Mojave and Keyboard Maestro 10.2 and to iterate through the 2800 macros I have. (I tried using a whose clause and couldn't find adequate syntax and therefore had to use the brute-force approach.)

  • It only returns a list of Macro IDs of Macros that have Typed-String Triggers.
  • Further filtering can be done if desired.
--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2023/02/16 17:47
# dMod: 2023/02/16 17:47 
# Appl: Keyboard Maestro
# Task: Find Macros That Have Typed Triggers.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Macros, @Typed, @Triggers
--------------------------------------------------------

set foundMacroList to {}

tell application "Keyboard Maestro"
   set macroList to macros
   
   repeat with theMacro in macroList
      set triggerList to triggers of theMacro
      repeat with theTrigger in triggerList
         if description of theTrigger contains "is typed" then
            set macroID to theMacro's id
            if macroID is not in foundMacroList then
               set end of foundMacroList to macroID
            end if
         end if
      end repeat
   end repeat
end tell

return foundMacroList

--------------------------------------------------------

From there munging the XML of the triggers ought not to be too difficult.

3 Likes

Could you not just:
Copy the trigger you want:

set TriggersList to {}

tell application "Keyboard Maestro"
	set MacroTriggers to every trigger of item 1 of (get selection)
	repeat with TriggerXML in MacroTriggers
		set end of TriggersList to xml of TriggerXML
	end repeat
end tell

TriggersList as text

Create a smart group or otherwise select the triggers you want to change. And then (when you are very, very sure) delete the existing triggers

tell application "Keyboard Maestro"
	repeat with CurrentlySelectedMacros in every item of (get selection)
		delete every trigger of CurrentlySelectedMacros
	end repeat
end tell

And paste the one you copied

I cop'd this from the forum at some point and did not capture the attribution..apologies to the genius I got this from!

1 Like

I have lost sight of this topic a bit. Thank you all for your contributions.

There is something I would like to get off my chest: This forum is a special place on the net in the best sense. Helpful and nice people everywhere you look. The mostly active contributors here deal with very advanced macros and often enough use cases that I can hardly comprehend when reading the posts. Most of my macros are different. Sequences of keystrokes, clicks and text additions, lots of text expansions, opening web pages and applications. I have no idea how many users use Keyboard Maestro at this level (maybe nobody has, as user behaviour is not tracked). For me, "Prepend action", "Append action", "Change setting of a common trigger" is not a particularly far-fetched feature for multiple selected macros. Being able to act on multiple selections beyond deleting etc. is something most Mac software I use offers. And no, I have no idea how long it would take to implement it and if this is an effective use of someone’s time. This was just user feedback. Thanks.