Duplicates should, I think, fall away automatically if we define the accumulation in terms of key:value
dictionaries (JS Objects) rather than ordered lists (JS Arrays),
seeding .reduce
with {}
rather than with []
.
So, perhaps, for example:
Plugin names with associated tags (sorted- no duplicates).kmmacros (2.8 KB)
Expand disclosure triangle to view JS source
(() => {
"use strict";
const
accumulation = Application(
"Keyboard Maestro Engine"
)
.getvariable("csvSource")
.split(",")
.reduce(
(a, x) => {
const [plug, tag] = x.split("__");
return Object.assign(
a,
{
[plug]: Object.assign(
a[plug] || {},
{[tag]: true}
)
}
);
}, {}
);
return Object.keys(accumulation).sort()
.map(
k => [k, ...Object.keys(accumulation[k]).sort()]
.join("_")
)
.join("\n");
})();