I see. From the code, I guess that you use the first word of every list item as a choice for the user and the rest are semicolon separated tags, metadata, whatever? In that case, I’d like to point out how one could do it better in JavaScript (in my opinion). The same approach (i.e. using an object) might be possible in AppleScript, but I do not know this language well enough.
No language competition here, only a kind of “educational code sample”.
const mapping = {
"Actionable": ["vAction:", "vGoal:", "vProject:"],
"Commonplace": ["cCommonPlace"],
"Email": ["cEmail"],
"Journal": ["cJournal"],
"Manuals":[],
"News: [],
"Receipt: ["aVendor", "cBudget"],
// etc.
}
const noteType = app.chooseFromList(Object.keys(mapping).sort(),
{withPrompt: "Special Note Type", multipleSelectionsAllowed: true});
/* noteType is a list of the user-selected items like "Actionable" etc. */
/* Loop over these items */
noteType.forEach(type => {
const tags = mapping[type];
/* tags is a list of strings associated with the selected item, eg "vAction:", "vGoal:", "vProject:" for "Actionable" */
// Do something with the strings in tags
}
}
That is, I think, a cleaner structure: A single object (mapping
) whose properties (aka “keys”) contain the strings you want to use as an array (aka “list”). No need to split up the list items at semicolons, since they are already separated. No need to sort the user choices alphabetically, since the sort()
call in the chooseFromList
method takes care of that.
Also, you’d not be limited to strings in the properties (at least in JavaScript) – you could use whatever object you need, even functions. So, if you’d want to rename a file, you’d use the function name like
…
"Actionable": [renameFile, "tag1"],
…
and check for the type of the list item (aka “array element”) instead of relying on a naming convention. Of course, if you use tags and custom metadata in there, you’d still need some kind of naming convention to discern between them.
A more complete sample to illustrate this approach can be found here: Using a single smart rule instead of Hazel (maybe)
I found an AppleScript example here: Getting data from AppleScript record with nested records - AppleScript - Late Night Software Ltd.