Convert Found Image Embedded to File Reference?

I use a ton of Found Image actions and If conditions in my macros with the images pasted into the macros (and stored in the Keyboard Maestro Macros.plist file). Obviously, that's not ideal for more than a handful of images. I'd like to convert those Found Image actions and If conditions from embedded images to references to external image files... But I'd rather not do every single one manually.

Does anyone have a macro, script, or method for:

  1. Extracting embedded images in Click At Found Image and If Found Image actions to external files, and/or;

  2. Converting those actions to reference the external image files with the File attribute of the action?

1 Like

Hey Pariah,

That's an extremely complex task with many variables. I'll be shocked if anyone has a comprehensive solution.

I would start out writing a macro to drive the Keyboard Maestro Editor's UI to do as much of the work as possible.

This AppleScript will let you go to the next enabled find-image or found-image action in the selected macro.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/10/01 21:01
# dMod: 2021/10/01 21:01 
# Appl: Keyboard Maestro
# Task: Select the Next Enabled Found-Image or Find-Image Action in the Selected Macro.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Selected, @Next, @Enabled, @Found-Image, @Find-Image, @Action
--------------------------------------------------------

try
   
   tell application "Keyboard Maestro"
      set selectedMacroList to selected macros
      
      if length of selectedMacroList = 1 then
         
         set selectedMacro to item 1 of selectedMacroList
         
      else if length of selectedMacroList < 1 then
         error "No macros were selected!"
      else if length of selectedMacroList > 1 then
         error "Too many macros were selected!"
      end if
      
      tell selectedMacro
         
         set actionList to actions whose enabled is true and (name contains "Found Image" or name contains "Find Image")
         
         if length of actionList ≥ 1 then
            set theAction to item 1 of actionList
            set enabled of theAction to false
            select theAction
         end if
         
      end tell
      
   end tell
   
on error errMsg number errNum
   set errMsg to errMsg & linefeed & linefeed & "Num: " & errNum
   if errNum ≠ -128 then
      try
         tell application (path to frontmost application as text) ¬
            to set ddButton to button returned of ¬
            (display dialog errMsg with title ¬
               "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to errMsg
      end try
   end if
end try

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

One could definitely write a macro to work with the XML of the selected macro or selected action, but doing it right would be difficult and time consuming.

You're probably better off writing one or more relatively simple helper macros and converting 10-20 macros or macro-actions at a time over a week or two.

-Chris

1 Like

Sounds like a plan. Thanks, Chris.

1 Like