Error "on performSmartRule (Error: Error: AppleEvent timed out.)" when running a smart rule wit a javascript script every minute

When I apply this rule manually it works without problems:

'use strict';

function renameDocument(record) {
  const app = Application("DEVONthink 3");
  var nameComponents = [];
  // create new name

  let date = app.getCustomMetaData({for: "Datum", from: record});
  if (date) {
    let year = date.getFullYear();
    let month = (1 + date.getMonth()).toString().padStart(2, '0');
    let day = date.getDate().toString().padStart(2, '0');
    nameComponents.push(year + "-" + month + "-" + day);
  }

  nameComponents.push(app.getCustomMetaData({for: "Kontakt", from: record}));
  nameComponents.push(app.getCustomMetaData({for: "Titel", from: record}));

  let newName = nameComponents.filter(Boolean).join(" | ");
  record.name = newName;
  //app.displayDialog(JSON.stringify(nameComponents));
  //console.log("newName: " + newName);
}

function moveDocument(record) {
  const app = Application("DEVONthink 3");
  const group = "/Dokumente";
  const db = app.getCustomMetaData({for: "Datenbank", from: record});
  if (!db) {
  	return;
  }
  const groupRecord = app.getRecordAt(`${group}`, {in: app.databases[db]}); 

  if (groupRecord) {
    //console.log(`${groupFound[0]}`);
	console.log("group found");
    app.move({record: record, to: groupRecord});
  }
}


function performsmartrule(records) {
  const app = Application("DEVONthink 3");
  app.includeStandardAdditions = true;

  /* Loop over the records selected by the smart rule */
  records.forEach(r => {
    renameDocument(r)
    moveDocument(r)
  })


}

/* anonymous self-executing function permits to run this in script editor etc. */
(() => {
  const app = Application("DEVONthink 3");
  performsmartrule(app.selectedRecords());
})()

But when It is triggered by Perform the following action: Every Minute, I receive an error:

14.04.2022, 23:20:10: Rename document and move to group	on performSmartRule (Error: Error: AppleEvent timed out.)

Any ideas?

You could try to remove the anonymous function at the end in the smart rule script.

I have removed the function. I still get:

(Error: Error: AppleEvent timed out.)

It has nothing to do with the script itself. The error occurs even if I don’t change the default script:

function performsmartrule(records) {
	var app = Application("DEVONthink 3");
	app.includeStandardAdditions = true;

	records.forEach (r => {
	})
}

As soon I include a Java Script script in the rule, I get the error:

LOG: Rename document and move to group (on performSmartRule (Error: Error: AppleEvent timed out.))

Any ideas?

I’m afraid not. Haven’t seen that before. About how many records are we talking here?

And is that happening when you run the rule manually or with your once a minute trigger?

One

The error only occurs when triggered by the once a minute trigger. When I run the rule manually, I don’t get a timeout. I don’t know why. Something must be different when running the rule by the one a minute trigger. :face_with_raised_eyebrow:

Have you tried running a rule with a javascript script using the once a minute trigger?

Nope. I’ve never seen a reason to run a smart rule at a fixed interval.

I tried to re-create your setup: A smart rule (in my case, selecting all documents in the Inbox) that is run every minute. The only action is an JavaScript. I do not see any error messages re time out.


I’m also unable to reproduce any timeout here either.
Select, Control-click, and disable the actions of other smart rules.
Do you see the timeout again?

The only reason I’m using the once a minute trigger, is that there is no trigger for custom meta data.

That is very strange. Currently I cannot reproduce it either, although I haven’t changed anything (except deleting some documents).

I will continue to monitor it. Thank you for your help.

1 Like

Why not Hourly or Daily to minimize the load?