Agenda and DEVONthink

Agenda and DEVONthink

Agenda is a web-based “date-focused note taking app” (their words) with a desktop companion. The following script adds the names and URIs of the currently selected DEVONthink records to a particular Agenda note as links. Clicking on them will then open the corresponding document in DEVONthink.

Note the usage of app.selectedRecords.referenceURL() and app.selectedRecords.name() ( line 8). This allows to get directly at the interesting data in a loop, without gathering them from each record individually. Though it might not matter in this case, this approach is supposed to be faster than looping over the records and retrieving the individual attributes.

(() => {
const app=Application("DEVONthink 3");
// StandardAdditions needed for openLocation at the end
app.includeStandardAdditions = true;

/* 
 * Get the URLs and names of the currently selected records
 */
const URLs = app.selectedRecords.referenceURL();
const names = app.selectedRecords.name();

/* 
 * Loop over all names
 */
names.forEach((n, i) => {
  
  // get x-devonthink URL for current record
  const URL = URLs[i];
  
  // URI encode the current record's name
  const nameEncoded = encodeURIComponent(n);

  /* 
   * Build x-callback URL for agenda. This appends the x-devonthink URLs 
   * and the records' names to the note specified in the "title" parameter. 
   * Change "title=Example%20Note" to "Identifier=xxx" if needed. 
   */
  const agendaNote = `agenda://x-callback-url/append-to-note?title=Example%20Note&text=[${nameEncoded}](${URL})`

  /* 
   * Open Agenda with the just modified note 
   */
  app.openLocation(agendaNote);
});
})()