Finding unused variables

Has anyone come up with a clever way to identify unused variables? Over time, I’ve built up quite a lot of cruft and it’s not a problem, strictly speaking, but it is ugly and makes it hard to browse through the macros.

Nik, I have written a macro that I am testing that will identify/list all variables, and optionally allow you to delete all variables NOT in a protected “keep” list.

If my testing goes well, it should be available later today.

Nik, after re-reading your post, I’m not sure what you mean by “unused variables”.

IAC, I have posted my macro which will give you a list of all Variables IF you CANCEL the confirmation. The main purpose is to delete all variable except those you want to keep.

[KM] DELETE All Variables Except Those on Keep List

One technical note: This list, which comes from JXA (or AppleScript) does NOT include all KM variables that show in the KM Preferences.

From Peter (@peternlewis):

The preference pane includes variables that are referenced by any macro or that have a value and that is not %Delete%.

The variables result from AppleScript includes variables that have a value and that is not %Delete%.