Scripted deletion of Keyboard Maestro variables is not to be undertaken lightly, but is not impossible, and can be done with a ‘Keep list’ of variables which are to be protected from deletion.
For example, the following script (set the Script Editor language selector to JavaScript), contains a list of the names of variables which should not be deleted.
If you run it, it returns a list of variables which are protected, and another list of the remaining variables which would all be deleted.
(if, that is, the value of delete option at the bottom of the script were ever edited to true)
If you do experiment with it, edit the keep list to whatever you need, checking carefully that your edit contains no typos or omissions whatsoever …
Possible, but not necessarily recommended.
(function (dctOptions) {
'use strict';
// KEEP LIST
// variables whose names are NOT listed here will be deleted
var lstKeep = [
'NoteApp',
'NoteDateAdjust',
'NoteExtn',
'NoteFolder',
'NotePrefix',
'soundDeviceONE',
'soundDeviceTWO',
'man page PDF folder',
'Shell command'
];
var kme = Application("com.stairways.keyboardmaestro.engine"),
kmVars = kme.variables,
lstVars = kmVars();
var lstToDelete = lstVars
.filter(function (v) {
return lstKeep.indexOf(v.name()) === -1;
}),
lstAllNames = lstVars.map(function (x) {
return x.name();
}),
lstZapNames = lstToDelete.map(function (x) {
return x.name();
});
if (dctOptions.delete === true) {
lstToDelete.forEach(function (x) {
x.value = '%Delete%';
})
}
if (dctOptions.list === true) {
return {
remaining: lstAllNames,
protected: lstKeep,
deletable: lstZapNames
};
}
})({
delete: false,
list: true
});