Thanks to the introduction of Local Variables with KM8 you might feel the need to clean up your variables inventory.
The macro deletes all variables from KM’s inventory except the ones excluded.
It makes use of the “Variables” collection, introduced with KM8.
The macro does the same as @ccstone’s AppleScript, but I found it to be considerably faster:
Deleting 1600 variables (as created e.g. by this macro) takes 5 minutes with the AppleScript, but just 8 seconds with this macro, on my MBP 2017. [1]
Clean-up Variables.kmmacros (27.5 KB)
You should configure the macro by customizing the Regular Expression for the exclusions.
Out of the box (as shown in the screenshot) any variable whose name starts with ENV_
or Persistent
is excluded from deletion.
The “Persistent” keyword is an example. Replace it with your personal pattern for variables you want to keep. However, do not remove the “ENV_” exclusion, since this prefix is used for environment variables, for example ENV_PATH
, ENV_PERL5LIB
.
Examples for exclusions:
# default:
^(?:ENV_|Persistent)
# a different prefix:
^(?:ENV_|MyMacro)
# an additional prefix:
^(?:ENV_|Persistent|MyMacro)
# only the prefix for environment variables:
^ENV_
To make the regex case insensitive prefix it with (?i)
, for example
(?i)^(?:ENV_|Persistent|MyMacro)
See the Regular Expressions reference for more variants.
If you don’t want to use Regular Expressions you can also use string conditions like this:
Note that this is always case _in_sensitive.
[1]: For an optimized version of the mentioned AppleScript see @ccstone’s post below. It runs as fast as this macro.