[KM] DELETE List of KM Variables [SUB-MACRO]

Bingo! You hit the nail on the head!
####Effective Immediately -- Quit Using the Macro at the top of this topic.

This seems like a bug in KM to me, because the sub-macro is reporting the Trigger of the main, calling Macro, instead of the Trigger for itself.

IAC, I now have a better method of cleanup that uses a script to accomplish the same thing.

Please see if this will work for you. Let me know if you have any questions.

##Macro Library   @KM Delete Variables with Script


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/7/7f40779ad47a975ca75b5078d52608635b201e6b.kmmacros">@KM Delete Variables with Script.kmmacros</a> (4.2 KB)

---

###ReleaseNotes

**How To Use**

1. Enter the KM Variable Prefix (like "TEST__") used with the variables in your macro that you want  to delete into the  "Set variable KMVarPrefix" box.
.
<img src="/uploads/default/original/2X/a/a32a047ec29b3edb132109b32721c68ad1cd3d1a.png" width="291" height="61">
.
2. Enter a list (one per line) of KM Variable names into the "Set variable KMVars_To_Delete" box.
.
<img src="/uploads/default/original/2X/f/f865d8b190e27b01cd6b90c1ac7a44a338bf92a9.png" width="301" height="60">

You can leave either/both empty if you wish.

---

<img src="/uploads/default/original/2X/5/51542799de34c2dec016c34b744372433d32bb6b.jpg" width="461" height="1162">

---

###AppleScript to Delete KM Variables

```applescript
tell application "Keyboard Maestro Engine"
  
  --- DELETE ALL KM VARIABLES WITH THIS PREFIX ---
  
  set prefixStr to getvariable "KMVarPrefix"
  
  if (prefixStr ≠ "") then
    set value of variables whose name starts with prefixStr to "%Delete%"
    --display notification "All KM Variables with PREFIX = '" & prefixStr & ¬
    --  "' have been deleted." with title "Keyboard Maestro Script"
  end if
  
  --- DELETE KM VARS IN THE VARIABLE "KMVars_To_Delete" ---
  
  set varsToDeleteList to paragraphs of (getvariable "KMVars_To_Delete")
  
  if (varsToDeleteList ≠ {}) then
    
    set varsToDeleteList to varsToDeleteList & {"KMVars_To_Delete"}
    
    repeat with oVar in varsToDeleteList
      setvariable (oVar as text) to "%Delete%"
    end repeat
    
    --display notification "All KM Variables in 'KMVars_To_Delete' have been deleted." with title "Keyboard Maestro Script"
    
  end if
  
end tell
```
3 Likes