How Do I Insert an Action as the First Action in 206 Macros Automatically

Hey @troy,

  • Sort your macros by NAME.
  • Select the ones you want to add the action to.
  • Run the AppleScript from an Execute an AppleScript action.

Be smart and test on 1 or 2 before going whole hog...

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/12/28 16:54
# dMod: 2022/12/28 16:54 
# Appl: Keyboard Maestro
# Task: Add a 0.1 Second Pause Action To Every Selected Macro.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Add, @Pause, @Action, @Selected, @Selection
--------------------------------------------------------

try
   
   set actionXML to text 2 thru -2 of "
   <dict>
      <key>ActionUID</key>
      <integer>12794614</integer>
      <key>MacroActionType</key>
      <string>Pause</string>
      <key>Time</key>
      <string>0.1</string>
      <key>TimeOutAbortsMacro</key>
      <true/>
   </dict>
   "
   
   tell application "Keyboard Maestro"
      set selectedMacroList to selected macros
      if length of selectedMacroList > 0 then
         repeat with theMacro in selectedMacroList
            tell theMacro
               set newAction to make new action with properties {xml:actionXML} at beginning
               # select first action
            end tell
         end repeat
      end if
   end tell
   
   display notification "Action Insertion Job Complete!" with title "AppleScript" subtitle "······················" sound name "Tink"
   
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

--------------------------------------------------------
7 Likes