What logic applies to a "Daily" smart rule?

I have a Smart Rule which runs daily. Today I noticed it hadn’t ran in three days, while I had DT open during those days. What is the logic for a “Daily” rule? E.g. does it run as soon as DT opens on a day it has not run yet? Or does it run on a random moment per day? And what happens when a rule errors? Is it tried again before the next day?

1 Like

Great Question!!!

What is the rule? A screencap could be useful.
And is the database it’s acting on open?

At least once every 24 hours. Depending on the availability (e.g. Mac sleeping, DEVONthink not running or databases closed) this might be delayed though.

Pretty standard rule:

Interesting question about the database being open - I thought it was, but maybe with closing/opening it was closed for a moment. I’ve now set it to Hourly and will see what happens.

Regarding the DB being open: I actually had to include some checks in my scripts to prevent it from running when the DB wasn’t open. Could it be that Smart Rules trigger when a database is not fully opened yet? This mail database takes a few moments to open and I get an error from my script sometimes when it tries to run and the DB isn’t open (which seems weird, because rules can only be active when the DB is open, right?)

A database can be only closed or opened. But I’m not sure right now whether the search scope is actually relevant without any conditions.

Did you notice whether you had any entry in the log? I regularly see scripts time out (I can’t remember the error message off hand - it’s Apple event timed out or something of the kind) when they are executed by smart rules when I am away from the Mac. So what I’m saying is that the smart rule may well be running, but the script itself fails to run. Having executed once, the smart rule would then settle back down at the fire place with a cup of tea…

The source of these scripts would be useful, maybe they just need a longer timeout than the default one?

It’s my auto-import mail rule - it’s a bit complex to workaround the DT3.8.3 smart rule limitations. I’ve now included a with timeout section to check if that solves it:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property pythonCmd : "/Users/mdbraber/.pyenv/shims/python3"
property pythonScriptPath : "/Users/mdbraber/iCloud Drive/Coding/Devonthink import mail/"
property pythonScriptName : "import-mail-to-dt.py"
property importCmd : pythonCmd & " " & quoted form of (pythonScriptPath & pythonScriptName)
property replaceScript : load script POSIX file "/Users/mdbraber/Library/Application Scripts/com.devon-technologies.think3/Smart Rules/Replace mail attachments.scpt"

on run
	tell application id "DNtp" to my performSmartRule(selection as list)
end run

on performSmartRule(theRecords)
	with timeout of 3600 seconds
		tell application id "DNtp"
			try
				-- Check if we the datase is open, because sometimes when starting
				-- DT it isn't open yet while the smart rule already runs (which is
				-- weird but might have to do with the opening taking longer?)
				set theDatabase to database "Mail 2020-now"
				show progress indicator "Importing new mail…"
				set theOutput to do shell script importCmd
				
				-- This is a workaround because 'perform smart rule' doesn't work
				-- from smart rules in DT 3.8.3 so we're including our script and 
				-- using tagged records. Ugly, but it works for now. This should
				-- be fixed in DT 3.8.4
				set theRecords to search "tags:import scope:\"Mail 2020-now\""
				-- This script replaces attachments and also strips the import tag
				-- (for now)
				replaceScript's performSmartRule(theRecords)
				
				hide progress indicator
			on error error_message number error_number
				hide progress indicator
				if error_number is not -128 then log message error_message
			end try
		end tell
	end timeout
end performSmartRule

I think the timing aspect of this question got overlooked. I have the same question creating a rule every day. I want to create a daily log in a specific group and I’d like it to be ready and waiting for me when I start work. If I start work at 8 AM, how would I ensure that it was available by that time, as opposed to 2 PM?

My solution is a script, launched via the Reminder feature

A reminder plus a script (see Annotations & Reminders inspector) are more suitable to guarantee a certain time. However, the computer still has to be running at the desired time or the reminder would get delayed.

E.g. I successfully use a daily reminder at 13:00 to download the astronomy picture of the day.

If I understand correctly, I would

  1. Create a Daily Reminder on the group where the notes go
  2. Attach an AppleScript that creates a new document and names it according to my naming rules

Yes, that sounds feasible.