Add as To Do as Reminders script is taking too long

I have been using this script “Add as To Do as Reminders” to add any DT item/document to Apple Reminders. However, I observe it takes a long time (average 10 seconds, some times 20 seconds) to just add a Reminder.

I know a little about AppleScript. Thus, I couldn’t figure out what is taking the time. I think most of the time are in the following codes, as I started to time only after I have answered to all the default prompt.

	-- 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

Is there anything we can do to improve the speed?

Please post the full script.

According to the dictionary, you should use make new reminder, although it appears to work even when you omit new.

Have you checked if theDueDate is formatted as date before being passed to Reminders? If it is, then theDueDate ≠ "" should in principle always return true.

Attached the full script here. The script is also available in the DEVONthink Scripts Folder, under Reminders.

-- 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
--> Added Custom Date option


-- Set properties
property pDaysIntoFuture : -1 -- Created to do will have a due date n days in the future
# I don't want the "Reminder" prefix
# I want a prompt that I can change Reminder text
property pPrefix : "Reminder" -- Prefix for the created to do item
(* property pDelays : {{displayname:"No due date", value:0}, {displayname:"Custom…", value:-1}, {displayname:"Tomorrow", value:1 * days}, {displayname:"In two days", value:2 * days}, {displayname:"In three days", value:3 * days}, {displayname:"In one week", value:1 * weeks}, {displayname:"In two weeks", value:2 * weeks}, {displayname:"In one month", value:4 * weeks}, {displayname:"In two months", value:8 * weeks}, {displayname:"In three months", value:90 * days}, {displayname:"In six months", value:180 * days}, {displayname:"In one year", value:365 * days}}
*)
# added Today
# No due date value should not be 0
property pDelays : {{displayname:"No due date", value:""}, {displayname:"Custom…", value:-1}, {displayname:"Today", value:0 * days}, {displayname:"Tomorrow", value:1 * days}, {displayname:"In two days", value:2 * days}, {displayname:"In three days", value:3 * days}, {displayname:"In one week", value:1 * weeks}, {displayname:"In two weeks", value:2 * weeks}, {displayname:"In one month", value:4 * weeks}, {displayname:"In two months", value:8 * weeks}, {displayname:"In three months", value:90 * days}, {displayname:"In six months", value:180 * days}, {displayname:"In one year", value:365 * days}}
property pDefaultDelay : "Today"

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}
	if theChoice is false then return false -- If the user pressed Cancel, exit
	if theChoice is missing value or class of item 1 of theChoice is not text then return false
	set theChosenListName to item 1 of theChoice
	
	-- Let the user choose when to receive the reminder
	-- Convert array into localized arrays
	set pLocalizedDelays to {}
	set pLocalizedDelayNames to {}
	repeat with theDelay in pDelays
		set pLocalizedDelays to pLocalizedDelays & {{displayname:localized string (displayname of theDelay), value:(value of theDelay)}}
		set pLocalizedDelayNames to pLocalizedDelayNames & {localized string (displayname of theDelay)}
	end repeat
	set theChoice to choose from list pLocalizedDelayNames with title (localized string "Set reminder") with prompt (localized string "Please choose when you want to get reminded of the item") & " \"" & theSummary & "\"" & (localized string "%choice prompt end%") & ":" default items {localized string pDefaultDelay}
	if theChoice is false then return false -- If the user pressed Cancel, exit
	set theDelayValue to pDaysIntoFuture -- Assume default
	try
		-- Find the number of days associated with the user's choice
		repeat with theDelay in pLocalizedDelays
			if ((displayname of theDelay) as string) is equal to (theChoice as string) then set theDelayValue to (value of theDelay)
		end repeat
	end try
	
	-- Calculate due date
	# need a way to test no due date, then set theDueDate to ""
	if theDelayValue = "" then
		set theDueDate to ""
	else if theDelayValue ≥ 0 then
		set theDueDate to (date (date string of (current date))) + theDelayValue
	else if theDelayValue < 0 then
		try
			set theDueDate to (date (text returned of (display dialog (localized string "Enter the due date") & ":" & return & (localized string "Example: 1/1/2017 10:45pm") default answer "")))
		on error
			return
		end try
	end if
	
	# Get the Reminders name/text
	set theSummary to (text returned of (display dialog "Enter the Reminders text: " default answer theSummary))
	
	-- 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

The vanilla script works without performance issue on my device. Since you have made modifications to it, those changes could be the cause of the lag. As far as I can see, the -- Add new to do to Reminders part has not been modified.

UPDATE: I experienced no lag with your version of the script, too.

Does rebooting your Mac solve the problem?

1 Like

Yes, I have tried rebooting my Mac. It doesn’t help.

I tried the vanilla script. It is about the same performance, 10 seconds.

Maybe it’s due to the existing amount of lists & reminders? Or a huge list of completed reminders that hasn’t been cleared yet? E.g. Reminders.app became much more responsive over here after clearing more than 10k of old reminders :joy: But still it’s slow, especially the sync.

1 Like

You are right. After clearing some lists and the completed reminders. The performance issue is gone. But…I only have about 2k completed reminders. After removing them, it is fast, about 1-2 seconds.

1 Like