What's the best way to run smart rules after I'm finished working with a record, and not while I'm working with it?

I just finished making a way to automatically extract only new PDF annotations.

However, the smart rule I made doesn’t work as well as I’d like:

Screen Shot 2022-03-02 at 2.25.32 PM

Namely, it’s hard to make it fire only after I’m finished with a file, not while I’m working with it.

Ideally I could set up conditions like:

  • Date modified is This Hour
  • Date modified is not in the last 15 minutes

If I’m working with something, I generally make some kind of change to the file at least every fifteen minutes. So the conditions above would fire on a record that has been “put down,” so to speak, but not before.

The “Perform actions after saving” thing kind of works, except many apps like to save often, so I find the rule fires often.

I feel like I’m missing something obvious here. Granted, everyone will have subtle differences in what it means to have “finished with” a file, but I’m hoping I can learn from someone else to apply to my use case.

You could simply add a few lines to the script to check the record hasn’t been edited it the past 15 minutes. Whilst the rule would then still trigger, the script would do nothing,

1 Like

Ha, thank you for the reminder—I think I’ve actually implemented that in the past… :roll_eyes:

I went with a heavy-handed approach, to make sure the script doesn’t fire within 15 minutes of interacting with the file whatsoever:

on performSmartRule(theRecords)

    repeat with eachRecord in theRecords

        	set recordModified to eachRecord's modification date
			set recordOpened to eachRecord's opening date
			set recordCreated to eachRecord's creation date
			set recordAdded to eachRecord's addition date
			if (((current date) - recordModified) > 15 * minutes) and (((current date) - recordOpened) > 15 * minutes) and (((current date) - recordCreated) > 15 * minutes) and (((current date) - recordAdded) > 15 * minutes) then
                -- do something
            end if

    end repeat

end performSmartRule

Still, it’d be nice if there was a way to do this without entering script-land.


I don’t know - I find it amazing that all these possibilities are available through scripting. It’s one of the great powers of DT.

1 Like

I think the “problem” might be that DT does not really have a concept of saving a record. You edit it, and whatever you do is immediately reflected in the content.

So going for a “has been modified in the last 1h but not the last xx minutes” approach might be the second best choice. If only DT would offer this kind of granularity. Or flexibility, like any time value instead of a fixed list of values.

1 Like

As much as I of course agree with you (as always :wink: ): If DT’s smart rules were a bit less limiting, a lot less scripting would be necessary. Like in this case: You can choose records modified within the last hour, but not withing the last 15 minutes. Simply because there’s no way to specify an arbitrary time value. I’m not sure that I see a technical reason for that, but it is forcing people intro script land unnecessarily, I think.


Thank you, I see your point :+1:t3:

1 Like

There are many things that can be accomplished via smart rules in their current state, far more than people give them credit for.
Also, things that lead easily into scripts are likely not very reducable in the first place.

And only @cgrunenberg could comment on the technical issues (which I’m sure are there, even if not immediately known to us).

There’s none in this case (but of course smart rules will never be able to do everything that can be scripted, not even almost).

If that’s the case, a bit more granularity wouldn’t go astray! Five or fifteen minute increments would be stellar, or even an integer text field.

If and when you get the chance, of course. :blush:

It’s always a matter of priorities (based on e.g. number of requests, amount of work, impact/visibility/usability of change and for how many users etc.)


Hi Ryan,
Do you have an updated version of the entire script you’d be willing to share. (I’m pretty weak on AppleScript, and I don’t seem to be placing this in the right place).
BTW, great job on the MPU podcast this week!

1 Like

I imagine you’re referring to the annotation extraction script—hoping to write up a blog post on the whole thing this week!

And thanks!


Ah ok -yes, the annotation extraction script. I’m not sure it will work given that I’m annotating on iPad then using an indexed bookends library (in iCloud), but the reduction in button pushing sounds appealing and smoother than my current Bookends→Drafts (with various strung together actions)→ Obsidian route. Look forward to the post, and apologies for tracking this down here (I’m one of those that nudged you on discord too).

1 Like

As long as the files, with annotations, are in DEVONthink 3 with smart rules, I think it should work. We’ll see when I get the chance to stitch it together!


Yes, I guess the trick is to have a smart rule or keyboard maestro or something to push the indexing on the main machine. (I don’t always work with my notes on the computer).

1 Like