Change KM Defaults Such as Pause Until Timeout, Failure Aborts Macro toggle, etc

Hey @tiffle,

Unfortunately Apple's AppleScript documentation is mediocre and incomplete.

It's also impossible for Apple to document how AppleScript works and quirks in all the various AppleScriptable applications.

Software developers also drop the ball by not documenting how their own software works.

Appended is a script that demonstrates what you want to do.

-Chris


Insert an Action ⇢ Compiled AppleScript.zip (13.4 KB)

Insert an Action ⇢ AppleScript Source Text
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/01/08 06:46
# dMod: 2021/01/08 06:46 
# Appl: Keyboard Maestro
# Task: Insert an Action After the Selected Action OR at end of Actions.
# Libs: None
# Osax: None
# Tags: @Applescript, @ccstone, @Script, @Keyboard_Maestro, @Insert, @Action, @After, @Selected
# Vers: 1.00b01
--------------------------------------------------------
(*

   NOTES:
   
   • This script will work as is – it contains a handler with a KM Action's XML.
   
   • The script demonstrates how to add an action AFTER the selected action
     OR at the END of the actions in the working macro – IF no action is
     selected.
   
*)
--------------------------------------------------------
property actionName : "DEBUG -- Display Variable in Window and Cancel Macro"
--------------------------------------------------------

tell application "Keyboard Maestro"
   
   --» Get first selected macro.
   set firstSelectedMacro to first item of (get selected macros)
   
   --» Get selected item.
   set selectionList to selection
   
   if length of selectionList > 0 then
      
      set {selectedItem} to selectionList
      
      if class of selectedItem = action then
         
         tell firstSelectedMacro
            set newAction to make new action with properties {name:actionName, xml:getSavedActionXML() of me} at after selectedItem
            select newAction
         end tell
         
      else
         
         tell firstSelectedMacro
            set newAction to make new action with properties {name:actionName, xml:getSavedActionXML() of me} at after its last action
            select newAction
         end tell
         
      end if
   end if
   
end tell

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on getSavedActionXML()
   set newActionXML to text 2 thru -1 of "
<dict>
    <key>ActionColor</key>
    <string>Orange</string>
    <key>ActionName</key>
    <string>DEBUG -- Display Variable in Window and Cancel Macro</string>
    <key>Actions</key>
    <array>
        <dict>
            <key>Action</key>
            <string>DisplayWindow</string>
            <key>MacroActionType</key>
            <string>InsertText</string>
            <key>StyledText</key>
            <data>
            cnRmZAAAAAADAAAAAgAAAAcAAABUWFQucnRmAQAAAC50
            AQAAKwAAAAEAAABsAQAAe1xydGYxXGFuc2lcYW5zaWNw
            ZzEyNTJcY29jb2FydGYxNTA0XGNvY29hc3VicnRmODMw
            CntcZm9udHRibFxmMFxmbmlsXGZjaGFyc2V0MCBIZWx2
            ZXRpY2FOZXVlO30Ke1xjb2xvcnRibDtccmVkMjU1XGdy
            ZWVuMjU1XGJsdWUyNTU7XHJlZDBcZ3JlZW4wXGJsdWUw
            O30Ke1wqXGV4cGFuZGVkY29sb3J0Ymw7O1xjc2dyYXlc
            YzA7fQpccGFyZFx0eDU2MFx0eDExMjBcdHgxNjgwXHR4
            MjI0MFx0eDI4MDBcdHgzMzYwXHR4MzkyMFx0eDQ0ODBc
            dHg1MDQwXHR4NTYwMFx0eDYxNjBcdHg2NzIwXHBhcmRp
            cm5hdHVyYWxccGFydGlnaHRlbmZhY3RvcjAKClxmMFxm
            czI2IFxjZjIgJVZhcmlhYmxlJWxvY2FsX0dvb2dsZVNl
            YXJjaFN0cmluZ0Z1bGwlfQEAAAAjAAAAAQAAAAcAAABU
            WFQucnRmEAAAAM7o1Vy2AQAAAAAAAAAAAAA=
            </data>
            <key>Text</key>
            <string>%Variable%local_GoogleSearchStringFull%</string>
        </dict>
        <dict>
            <key>Action</key>
            <string>CancelThisMacro</string>
            <key>MacroActionType</key>
            <string>Cancel</string>
        </dict>
    </array>
    <key>MacroActionType</key>
    <string>Group</string>
    <key>TimeOutAbortsMacro</key>
    <true/>
</dict>
"
   return newActionXML
end getSavedActionXML
--------------------------------------------------------
1 Like