A script to automate reminders

I know there is a script to manually send a note to reminders but is there anything that will totally automate the process meaning If I create a note in a particular group or assign a particular tag or label to it?

Thanks

Embed the following script in a smart rule which triggers on moving to a specific group, marking with a label or whatever.

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set theDate to creation date of theRecord
			-- (seconds * minutes * hours * days * months)
			set theDate to (theDate + (60 * 60 * 24 * 30 * 6))
			tell theRecord to make new reminder with properties {schedule:once, alarm:notification, due date:theDate}
		end repeat
	end tell
end performSmartRule

Adjust the time as required - currently it is set to remind you 30*6 days from the creation date of the document.

(I may have misunderstood you - this sets a reminder in DT - was that what you wanted, or did you want a reminder in the Reminders App?)

2 Likes

Wow thatā€™s nice and handy.

I did mean to send to the Apple reminders app. So when I set a note or any nite within a group it automagically creates a reminder in Apple.

In which case my response was useless, sorry about that :smiley:

Iā€™m just looking at the script for sending to Reminders app. Obviously you could trigger that script with a smart rule - is the only problem that the script is requiring input from you? If Iā€™m reading it correctly, the script asks you to choose a Reminder list and the due date, is that right? You could modify the script to automate both those things easily, I think. Is that whatā€™s required?

(quick and dirty: the lines which set a variable using ā€œchoose from listā€ could simply be replaced so as to set the variable to a predefined choice; that would obviate some of the code, but leaving it in wouldnā€™t do much harm)

What do you want to accomplish? I.e. what task do you want to be reminded about?

In iOS you could create a note in DTTG using a URL-scheme with Shortcuts and simultaneously/automatically create a new reminder in the Reminder app, but Iā€™m not sure whether those can be ported to macOS.

I donā€™t think your script is useless. Iā€™ll use it.

I was just tying to completely automate the process of entering a note into my tasks folder and having it show up on my calendar without me possibly forgetting to do anything else.

Also it would be nice to be able to add tasks on my phone and when they sync to Mac automate the reminders function as well. But I donā€™t know if that can happen.

Doing it on the iPad or iPhone is really the ultimate plan. I use an application called Daylite to display all my tasks and events. But I like to enter my tasks into dt3 or dttg since I am able to store much more information with the task. But I donā€™t want to lose track of them.

Currently I enter all my tasks into a group simply called tasks.

So you would like a reminder in the Reminders app for every task which is placed in the group called tasks? Does the reminder need a due date?

-- Script to add a selected record to Reminders as a to do
-- Written by Eric Bƶhnisch-Volkmann, Version 1.1, Sep 12, 2012
-- Ā© 2010ā€“2014 DEVONtechnologies, LLC
-- Modified October 28, 2016 by Jim Neumann / BLUEFROG / DEVONtechnologies, LLC
-- Modified by blanc (remove user input)

-- Set properties
property pPrefix : "Reminder" -- Prefix for the created to do item
set theDueDate to ""

-- Import helper library
tell application "Finder" to set pathToAdditions to ((path to application id "DNtp" as string) & "Contents:Resources:Template Script Additions.scpt") as alias
set helperLibrary to load script pathToAdditions

try
	-- Get the selection
	tell application id "DNtp" to set thisSelection to the selection
	
	-- Error handling
	if thisSelection is {} then error localized string "Please select a document or group, the try again."
	if (length of thisSelection) > 1 then error localized string "Please select only one document or group, then try again."
	
	-- Get and format the data we need
	set pLocalizedPrefix to localized string pPrefix
	tell application id "DNtp"
		set thisItem to first item of thisSelection
		set theSummary to (pLocalizedPrefix & ": " & name of thisItem) as string
		set theURL to (reference URL of thisItem) as string
	end tell
	
	-- Let the user choose the reminder list
	tell application "Reminders"
		set theListNames to {}
		repeat with theList in the lists
			set theListNames to theListNames & {name of theList}
		end repeat
	end tell
	if (count of theListNames) = 0 then error (localized string "Please set up at least one list in Reminders.")
	-- set theChoice to choose from list theListNames with title (localized string "Choose list") default items {item 1 of theListNames}
	-- CHANGE ITEM NUMBER to put reminder in different reminder list
	
	set theChosenListName to item 1 of theListNames
	
	-- you can change the reminder date/time here - change weeks to days or hours, change the number of weeks or hours. The 28800 bit is (60 s * 60 min * 8h) to make 8 o'clock
	set theDelayValue to (1 * weeks) + 28800
	-- Calculate due date
	
	set theDueDate to (date (date string of (current date))) + theDelayValue
	
	-- Add new to do to Reminders
	tell application "Reminders"
		tell list theChosenListName
			--Create new to do
			if theDueDate ā‰  "" then
				set theEvent to make reminder with properties {name:theSummary, remind me date:theDueDate, body:theURL}
			else
				set theEvent to make reminder with properties {name:theSummary, body:theURL}
			end if
			show theEvent -- Show new to do item in Reminders so that the user can edit it right away
			activate
		end tell
	end tell
	
on error errMsg
	
	display alert (localized string "Error when adding item to Reminders") message errMsg
	
end try

This script will add a reminder to the Reminders app for one week from now, at 08:00. If you put it in an appropriate smart rule it should do what you want. If it goes out and makes coffee and boils an egg, however, I cannot be held responsible (but it works here for me).

(as I said, somewhat quick and dirty, there are a few more lines of code which could be cleaned up)

It would be possible to add a failsafe to this: if you were to set up custom metadata (e.g. called ā€œRemSetā€), then the script could e.g. set RemSet to 1 and not set up another reminder for that document so long as that ā€œ1ā€ remains. That would reduce the risk of setting multiple reminders for one document (thatā€™s especially important if you canā€™t narrow down your smart rule suitably)

I appreciate the work but I donā€™ think I have the knowledge to get this working. I pasted it into the embedded edit script area but I donā€™t know if it should go within the existing script or replace it.
And when I paste it in it doesnā€™t color code. I donā€™t want to take up your time with this. But I see I am missing some basic knowledge of scripting in DT3.

John

Turns out nor do I :wink: the embedded script canā€™t handle the date command (oh, yes, I remember). Iā€™ve ā€œcleaned upā€ and simplified the script now and attached it here zipped. You need to unzip it, and then add the script file to DEVONthinkā€™s (DT) smart menu script folder like so: in DT click on the script icon in the menu (itā€™s on the left of the Help menu); select ā€œOpen Scripts Folderā€; it contains a folder ā€œSmart Rulesā€; drop the script in the folder ā€œSmart Rulesā€.

Now when you set up a smart rule and as the action select an external script, you will be able to select our new script called ā€œAuto-Add as Reminderā€ from the dropdown list.
Whether or not you use both the internal and external reminders is up to you of course. Your smart rule can run both scripts.

I have actually tried all those steps now, and it works for me. Sorry for not having tried the previous script embedded, then I would have noticed myself that it wasnā€™t going to work without modification.

As I said, your rule needs to make sure it only runs on each file once (otherwise youā€™ll have lots of remindersā€¦); if you set up a custom metadata (DT preferences/Data; Iā€™ve called mine ā€œIsReminderSetā€), then you could set your rule to look like this:

Obviously, you might want to change on which group the smart rule acts. You might want it to trigger ā€œAfter Synchronisationā€ if you are adding items to the group with DTTG on iOS. As a one-off, you may also want to set the ā€œIsReminderSetā€ to 1 with a smart rule on all files already in the folder which is acted on by the smart rule, just so as you donā€™t get reminders for that which is already in there today.

If you open the script, you can change both the point in time of the reminder (currently one week on the future at 08:00) and the reminder list - both parts of the script are marked with a comment. Note: DT caches the scripts on startup, so any changes you make to the script arenā€™t reflected until you restart DT.

Auto-Add as Reminder.zip (5.9 KB)

Try it out - again, Iā€™m not going to be responsible for the script taking meth and playing loud music, but itā€™s not done any harm here :smiley: Let me know if you run into any problems.

And thanks to all those who have helped me code these past few days - the great thing about knowledge is we all have differing degrees and selections of it, and can share and help out.

As homework, you could try and integrate writing to metadata into the script - that way the metadata bit would only be set if the script is actually successful - currently, if it failed with an error, then the bit would still be set, and the script wouldnā€™t run on that file again (which in practice probably actually wonā€™t be a problem).

2 Likes

Iā€™m aware Iā€™m interweaving with the AppleScript approach of @blanc, but nevertheless I have the idea you might be putting the cart before the horse somehow.

Itā€™s always difficult to understand someoneā€™s workflow without actually seeing it, but coukd you explain what happens in what order? You use Daylight, Reminders and DTTG, and sync the latter to DT, correct?

So youā€™ve just been triggered/asked to do something, but you donā€™t want or cannot do if right now. So you set a reminder somewhere and that apparently references information you can store in DT/DTTG but not in Reminders.

How do you set the reminder currently?

I completely agree with your sentiment - always ask the workflow first, and then offer support for that workflow. Iā€™m just enjoying coding to be honest - and the original question included the words ā€œscriptā€ and ā€œautomateā€ :smiley:

2 Likes

Well, Iā€™m pretty impressed with the speed at which you accomplished that to be honest :+1:

I also perfectly understand the need to quickly reference some information when reviewing or performing a task as @Johncesta mentions , but I use a DT(TG) UUID to do that. A UUID is portable between DTTG and DT, as are the tasks in Reminders if you sync them over iCloud.

In short I use one app to do task management (although I personally donā€™t use Reminders) and one app to store/reference information, and have them reference each other with a UUID or URL-scheme where necessary. That puts most things in one spot and declutters my workflow considerably.

I lose interest in things if they donā€™t move quickly enough (making me useless at some tasks, I must admit) :see_no_evil: It took me an hour yesterday to figure out how to send a document path to another application in one of my scripts, so Iā€™m still struggling with the basics, really.

The script for John adds a link (x-devonthink-item) to the document in the reminder, so in that sense itā€™s similar to what you are doing, if I understand you correctly. That link is also displayed in Reminders in iOS, but is not a valid link there, unfortunately. What is lacking is a link back from the document to the reminder. Anyhow, itā€™s nice to see how ppl are doing things, picking up ideas here and there and then shaping things into a personal ideal - which is why itā€™s great if a bunch of ppl chip in on threads like this one (I hope @Johncesta agrees :D)

I just pasted x-devonthink-item://UUID in Reminders in iOS (the URL field) and that opens the corresponding document in DTTG.

Wouldnā€™t it be possible to search for that reminder with a Shortcut that is passed the DTTG UUID? That reminder can be opened with some URL-scheme x-apple-reminderkit://, but it requires the UUID of the reminder to open it. Iā€™ve never used it, so Iā€™m not sure how one obtains that.

DTTG UUID > Shortcuts > Search Reminder containing > Open reminder

But if one uses Reminders or any other app to handle the task status, I donā€™t immediately see a need for DTTG to open the reminder. Hence the question what specific steps are taken in @Johncestaā€˜s workflow.

That works - but itā€™s not scriptable; ie it is possible to send the link to the body of the reminder, but not to the url-field of the reminder - Apple seems to have forgotten that property (at least, itā€™s not in the dictionary). And whilst macOS recognises the link as a link even in the body of the reminder, iOS does notā€¦ woohoo.

That might very well be one of the reasons I personally donā€™t use the Reminders app for my reminders :slight_smile:

My challenge is that the application I want to use is called Daylite. It can sync reminders from apple reminders. So apple reminders is used as a bridge to Daylite.

If I can use reminders than I can sync my reminders to almost any other calendar or todo application or PIM on the Mac that I like.

Yea, one needs to copy the url an move it to the URL field.