[KM] DELETE All Variables Except Those on Keep List

Hey Costa,

Here's the simple way to handle that.

property keepList : items 1 thru -2 of {¬
   "click_X", ¬
   "click_Y", ¬
   "ENV_PATH", ¬
   ""}

tell application "Keyboard Maestro Engine"
   repeat with theVariable in (get variables)
      set varName to theVariable's name
      if varName is not in keepList then
         setvariable varName to "%Delete%"
         try
            delete varName
         end try
      end if
   end repeat
end tell

I've used vertical list notation, because it's easier to sort and maintain than the horizontal. The last null-string item ("") in the list is pruned on compile and is there to make the list that much more readable.

-Chris

[ Edit: 2016/07/12 04:01 CST – minor bug-fix. ]

3 Likes