Quantcast
Channel: DEVONtechnologies Community - Latest posts
Viewing all articles
Browse latest Browse all 16117

Ability to choose alias from a group specific drop down list

$
0
0

That’s one of the cases where a JavaScript version is a lot shorter and simpler:

(() => {
  const app = Application("DEVONthink 3");
  const currentApp = Application.currentApplication();
  currentApp.includeStandardAdditions = true;
  const currentWindow = app.viewerWindows[0];
  let tagSet = new Set();
  currentWindow.root.children().forEach(record => {
    tagSet = tagSet.union(new Set(record.tags()))
  })
  const sortedTags = Array.from(tagSet).sort();
  const chosenTags = currentApp.chooseFromList(sortedTags,{ withPrompt: "Specify Tags", multipleSelectionsAllowed:true});
  console.log(chosenTags);  
})()

Fun facts:

  • There’s a Set datatype in JavaScript, so we use that instead of checking if an element exists already in the tag list
  • We can use the union method on the Set object, since Apple has that already implemented in its JavaScript engine. It (the method) takes care of adding every element only once.
  • From the Set, we can easily build an Array object, which can then be sorted with the aptly named JavaScript method

That is not to say that the AppleScript code is bad – just a bit chatty :wink:


Viewing all articles
Browse latest Browse all 16117

Trending Articles