A script to automate reminders

Ok, I’m going to jump on this bandwagon here, or maybe a slightly different one. Still, they’re headed in the same direction.

Got a fairly lengthy discussion going on my workflow here: https://discourse.devontechnologies.com/t/dt-things-mindnode-spark-and-bear/. That’s not super relevant except to note that I’ve made a ton of progress figuring out how to tie my admittedly disheveled notes together.

One of the final steps would be to do exactly this, but with Things–I have a smart rule set up to execute anytime a note with “Send to Things” is saved, and I tried copying the script that is used in the menu to the “External” folder that is referenced when building a new smart rule, but it failed: Dropbox Capture.

I assume this is not a surprise to those who script, but would anyone be able to provide me some guidance on how to adapt that “Add as To Do to Things” item to be used with a smart rule?

Thanks in advance!

To quote TFM:

Smart Rule scripts are defined by a specific handler: on performSmartRule(var) , where var is the variable representing items matched by the smart rule.

The script in the menu bar does not have this handler defined, so it is not run (and that’s probably also the reason for the error you see).

You should make a copy of the menu bar script and adjust it so that it defines this handler (on performSmartRule). It would look something like this

on performSmartRule(records) 
  set thisSelection to records
  tell application id "DNtp"
	-- Error handling
	if thisSelection is {} then error localized string "Please select a document or group, then try again."
	if (length of thisSelection) > 1 then error localized string "Please select only one document or group, then try again."
end performSmartRule

I’m not a fan of AppleScript, so I just sketched the approach here. You’ll have to read and understand the original script to implement the on performSmartRule handler correctly. Or just put all the code inside it and only adjust the tell application id "DNtp" ... line accordingly.

I don’t follow links of this type - that may be exaggerated or even not particularly useful, but it’s a simple principle in my security concept.

I’m happy to try and assist you if you actually include the pertinent information in the thread; images, code etc. can be included inline in the post.

Sometimes new users are not allowed to post images here. So, I guess, putting them on Dropbox and linking to them is just a way to get around this limitation. Not to criticize your approach, of course. And the poster could simply have quoted the error message here, the image didn’t do anything else.

Anyway: They’re trying to run a normal script inside a smart rule. Which is of course not going to work.

Quoting the error message has the additional advantage of offering food for the search engine. You are quite right to point out the limitations new users face, thanks for the reminder; the poster in this thread has reached trust level 1, so should be able to post images, I think.


Included it inline here.

FWIW, I’ve always required issues, requests, etc submitted to my team to have a screenshot, especially if there’s an error message. I don’t need clients trying to type it in, too prone to error, and screenshots usually give additional context that helps with troubleshooting. Same for myself; my screenshots get filed to Dropbox for any number of reasons and that link automagically hits my clipboard.

In any case, the error is “on performSmartRule (Error -1708)”. A google search seemed to indicate this was a pretty common and maybe not particularly helpful error, which is not a surprise, since I’m well out of my comfort zone.

Any help is certainly appreciated.

Here’s hoping that a future iteration of Discourse will OCR text in posted images and therefor find them when searching. Thanks for the post.

Be so kind as to post a screenshot of your smart rule and the script you are using, please. @chrillek has probably already solved the problem, however - you could certainly play with the suggested solution and post back if you run into additional problems.

Usually, error messages can be copy pasted, avoiding any typos. Makes them easy to search for, too.

EDITED: Including the script and a couple updated screenshots.

Oh, sure thing. Here’s the whole thing (in context, as per my best practices that I didn’t actually follow in the earlier screenshot…).

Per @Blanc 's point, here’s the copy and paste from the error dialog:

6/25/22, 10:20:02 AM: ~/Library/Application Scripts/com.devon-technologies.think3/Smart Rules/Auto Add as To Do to Things.scptd on performSmartRule (Error -1708)

And, the script, which in this version is just a duplicated of the Add as To Do to Things.scptd.
Auto Add as To Do to Things.scptd.zip (13.7 KB)

Again, I appreciate the help. DT is clearly the answer I’ve been looking for over the past few months and is working extremely well for my use case; nailing down this automation will solve for one the most vexing challenges that I’ve had.


(Sorry for the multiple edits.)

I already did explain what’s going wrong. Did you follow up on that?

Revise that–thought you had said you had explained what was going wrong with the dates. Yes, I did follow up on that, and wasn’t sure how to place the code inside the on performSmartRule handler. Sorry for my confusion!

it should be the case that you want to put the following below the last property line:

on performSmartRule(records) 
  set thisSelection to records

and then place

end performSmartRule

immediately above on error errmsg.

You also need to change the line tell application id "DNtp" to set thisSelection to the selection to tell application id "DNtp"

(this is based on the version of the script I have locally; as I mentioned, I don’t follow links to downloads)

1 Like

Thanks, Blanc. Didn’t get it working on initial pass, but I’ll have time this weekend to sit down and work through it more methodically. I’ll do that and post the follow up here. Appreciate your @chrillek 's help.

  • That script processes the selection. A smart rule doesn’t (or shouldn’t) process the selection. The parameter in the handler provides the input to the script, e.g.,
on performSmartRule(theFiles)
-- do stuff
end performSmartRule
  • A smart rule is generally meant to run headlessly, i.e., without user intervention.

  • If you choose to apply this as a smart rule with the user interaction, you’ll either have to choose one date to apply to all tasks or be prompted for a date for each task. The latter is definitely not something we’d advocate but that’s up to the individual’s opinion.

1 Like