How to debug persistent failure to trigger Reminder (Monterey 12.4, DT3 3.8.4)

Hi,

I know this has been addressed before, but not seen any applicable solutions.

I have a reminder set on a Group ‘Journal’ to create a new daily journal at 7am every morning, using an external template script.

FWIW, the Reminder is set to (it’s been triggered manually today, so the next time is tomorrow):

The behaviour:

  1. It is never triggered automatically, even when the computer is on at that time and DT3 is running. This morning it still hadn’t triggered by 10am, 3 hours later.

  2. I can always trigger the script if I manually advance the reminder time to a couple of minutes in the future. (E.g. at 10.03 this morning, I set the reminder to 10.04 and the script worked).

As far as I can see, this means that the template script itself is fine and is working properly (as it should – I mostly nicked it off Jim…) – so it doesn’t seem worth including the script here.

The problem seems to be therefore that the trigger isn’t being pulled at the correct time.

I have no diagnostics on this: the new journal just doesn’t appear, with no message appearing in the Log Window, or as far as I can tell, the Activity Window.

So, the first question is: what steps can I take to log what’s happening (or not happening)?

E.g. are there special logging preferences and/or what should I insert in the script to help the process?

Many thanks,

David

Is the database also opened? Although it shouldn’t be necessary to manually do this. The source of the script would be also useful.

Hi Christian,

Yes, the database is always open when the script is set to run.

The script is below. As I said, it is always triggered fine when I set the time manually by advancing it a couple of minutes ahead of the current time, but it always fails when it’s set to the next day to trigger ‘naturally’. The script file is properly installed in the Application Script ... Reminders directory – it’s not aliased, if that matters.

I use CloudKit to sync all the databases. The log window tells me:

Screenshot 2022-07-15 at 10.35.13

but the 7.24.44 error is half an hour after the script was supposed to be triggered. Could it be related?

Many thanks for your help.

(*
	Based on script by Chuck Lane October 2, 2013
	https://discourse.devontechnologies.com/t/daily-journal-script/16509
	Updated and optimized for DEVONthink 3 by Christian Grunenberg April 30, 2019
	Localized by Eric Böhnisch-Volkmann June 28, 2019
	Revised for Markdown by Christian Grunenberg Oct 19, 2020
*)

property numHeadlines : 4
property journalDatabase : "/Users/david/Databases/DT3/DB Docs.dtBase2"
property nationalNews : "http://feeds.bbci.co.uk/news/rss.xml"
property localNews : "www.chesterchronicle.co.uk/news/?service=rss"
--Weather Condition
property weatherAPI : <redacted>

on performReminder(myGroup)
	
	set theWeather to getWeather() as text
	
	-- 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
	
	-- Format the time, strip out the seconds but keep the AM/PM indicator
	set theDate to current date
	set theTime to time string of theDate
	if (theTime contains "AM" or theTime contains "PM") then
		if character 5 of theTime is ":" then
			set theTime to (characters 1 through 4 of theTime) & (characters 8 through 10 of theTime) as string
		else
			set theTime to (characters 1 through 5 of theTime) & (characters 9 through 11 of theTime) as string
		end if
	else if character 5 of theTime is ":" then
		set theTime to (characters 1 through 4 of theTime)
	else
		set theTime to (characters 1 through 5 of theTime)
	end if
	
	-- Format the month number
	set numMonth to (month of theDate as integer) as string
	if the (length of numMonth) < 2 then set numMonth to "0" & numMonth
	
	-- Format the day, calculate suffix for English if needed
	set theDay to day of theDate as string
	set shortDay to theDay -- shortDay won't have a leading zero
	if the (length of theDay) < 2 then set theDay to "0" & theDay
	set daySuffix to ""
	
	set suffixList to {"st", "nd", "rd"}
	set theIndex to last character of theDay as integer
	if (theIndex > 0) and (theIndex < 4) and the first character of theDay is not "1" then
		set daySuffix to item theIndex of suffixList
		
	end if
	
	-- Format the year
	set theYear to year of theDate as string
	
	-- Format month and weekday names (localized)
	
	set theMonth to month of theDate as string
	set longWeekday to weekday of theDate as string
	set shortWeekday to characters 1 thru 3 of longWeekday
	
	tell application id "DNtp"
		try
			activate
			
			-- Set the location for the new journal in /Journal/Journal <current year>
			set theDatabase to open database journalDatabase
			set myGroup to create location "/Journal/Journal " & theYear
			
			-- Check to see whether we have a ./media group and if not, create it
			if not (exists record at "/Journal/Journal " & theYear & "/" & "/media") then
				create record with {name:"media", type:group} in myGroup
			end if
			
			create location (location of myGroup) & (name of myGroup) & "/media"
			
			-- Calculate today's date in the form YYYY-MM-DD Day (2022-02-01 Mon) and make it the document name
			set dateToday to theYear & "-" & numMonth & "-" & theDay & " " & shortWeekday as string
			set recordName to dateToday
			
			-- Set up a list of markdown documents in journal year group with the same name as the current date
			set myRecords to children of myGroup whose name is recordName and type is markdown
			
			-- If there aren't any, we can go ahead and create the new one
			if ((count of myRecords) is 0) then -- Create the document from scratch
				
				-- Create the # Main headline string			
				set theHeadline to (longWeekday & ", " & shortDay & daySuffix & " " & theMonth & " " & theYear)
				
				-- Call the national and local news functions to populate the relevant lists
				set myNewsNational to my getNewsNational()
				set myNewsLocal to my getNewsLocal()
				
				-- Build the YAML header string
				set theHeader to "---  " & return & "Title: " & dateToday & "  " & return & "Base Header Level: 1  " & return & "Keywords: journal  " & return & "---  " & return & return
				
				-- Build the weather line
				set theWeatherLine to "<p style=\"text-align:center;font-size:small;font-style: italic\">Created at " & theTime & " when the weather was " & theWeather & "</p>" & return & return
				
				--Build the main content block
				set theContent to theHeader & "# " & theHeadline & return & return
				
				set theContent to theContent & theWeatherLine & return & return
				-- set theContent to theContent & "{{TOC:2-5}}" & return & return
				
				set theContent to theContent & "## Today" & return & return
				
				-- Create the National News block
				set theContent to theContent & "### National News" & return & return
				
				-- turn the news list into markdown links
				repeat with i from 1 to (count of items of myNewsNational) by 2
					set theContent to theContent & "[" & item i of myNewsNational & "]"
					set theContent to theContent & "(" & item (i + 1) of myNewsNational & ")   " & return
				end repeat
				
				-- Create the Local News block
				set theContent to theContent & return & return & "### Local News" & return & return
				
				-- turn the news list into markdown links
				repeat with i from 1 to (count of items of myNewsLocal) by 2
					set theContent to theContent & "[" & item i of myNewsLocal & "]"
					set theContent to theContent & "(" & item (i + 1) of myNewsLocal & ")   " & return
				end repeat
				
				-- Create the Must do today block
				set theContent to theContent & return & return & "### Must do today" & return & return
				set theContent to theContent & "- [ ]  " & return & return
				set theContent to theContent & "## Daily Notes" & return & return & return & return
				
				-- Create the References block: this won't appear in the html / output, but will be visible
				-- in the markdown to set off reference links from the rest of the document
				set theContent to theContent & "[Reference links]: #" & return & return
				
				-- Create and populate the document with its content and default tags				
				set myRecord to create record with {name:recordName, content:theContent, type:markdown, tags:theYear & "," & theMonth} in myGroup
				
			else -- Record already exists, just add new weather/time header
				set myRecord to item 1 of myRecords
			end if
			
			-- Not sure what this does, or why it does it…
			set theContent to plain text of myRecord
			
			-- open the record in a new document window
			open tab for record myRecord
			
			
		on error errMsg number errNum
			display alert (localized string "An error occured when adding the document.") & space & errMsg
		end try
		
	end tell
	
end performReminder


--  Functions

--Get the nationalnews headlines
on getNewsNational()
	-- Clear the variable
	set myNewsNational to {}
	
	tell application id "DNtp"
		try
			-- Download the full feed in markdown format
			set getNewsSource to download markup from nationalNews
			
			-- Trim the feed to the top X lines
			set getNewsFeed to items 1 thru numHeadlines of (get items of feed getNewsSource)
			
			-- Run through the list to 
			repeat with theItems in getNewsFeed
				set end of myNewsNational to title of theItems
				set end of myNewsNational to link of theItems
			end repeat
			
		end try
		return myNewsNational
	end tell
end getNewsNational

--Get the local headlines
on getNewsLocal()
	set myNewsLocal to {}
	
	tell application id "DNtp"
		try
			set getNewsSource to download markup from localNews
			
			set getNewsFeed to items 1 thru numHeadlines of (get items of feed getNewsSource)
			
			repeat with theItems in getNewsFeed
				set end of myNewsLocal to title of theItems
				set end of myNewsLocal to link of theItems
			end repeat
			
		end try
		return myNewsLocal
	end tell
end getNewsLocal

--Get Weather Conditions
on getWeather()
	tell application "JSON Helper"
		try
			(* Get my latitude and longitude*)
			tell application "Location Helper"
				set listCoords to get location coordinates
				set _lat to item 1 of listCoords as text
				set _lon to item 2 of listCoords as text
			end tell
			
			set Weather_Display to ""
			
			(* Get current weather from OpenWeather *)
			set getWeathersource to fetch JSON from ("https://api.openweathermap.org/data/2.5/weather?lat=" & _lat & "&lon=" & _lon & "&exclude=minutely,hourly&units=metric&appid=" & weatherAPI)
			set getWeather to "High: " & temp_max of main of getWeathersource & return & return & "Low: " & temp_min of main of getWeathersource & return & return & "Current: " & temp of main of getWeathersource & return & return & "Humidity: " & humidity of main of getWeathersource & return & return & "Conditions: " & description of item 1 of weather of getWeathersource
			
			set Current_Temp to (round (temp of main of getWeathersource)) & "°"
			set Daily_Temp to "Min " & (round (temp_min of main of getWeathersource)) & "° " & "to a " & "Max " & (round (temp_max of main of getWeathersource)) & "°"
			
			set Weather_Display to "## Weather" & return & return & getWeather & return & return
			
			if Weather_Display contains "clear" then
				set WeatherIcon to "☀️"
			else if Weather_Display contains "thunderstorm" then
				set WeatherIcon to "🌧⚡️"
			else if Weather_Display contains "drizzle" then
				set WeatherIcon to "🌦"
			else if Weather_Display contains "rain" then
				set WeatherIcon to "🌧"
			else if Weather_Display contains "snow" then
				set WeatherIcon to "❄️"
			else if Weather_Display contains "sleet" then
				set WeatherIcon to "❄️"
			else if Weather_Display contains "mist" then
				set WeatherIcon to "🌫"
			else if Weather_Display contains "fog" then
				set WeatherIcon to "🌁"
			else if Weather_Display contains "squalls" then
				set WeatherIcon to "💨"
			else if Weather_Display contains "smoke" then
				set WeatherIcon to "🔥"
			else if Weather_Display contains "haze" then
				set WeatherIcon to "🌫"
			else if Weather_Display contains "clouds" then
				set WeatherIcon to "⛅️"
			else
				set WeatherIcon to "🌡"
			end if
			
			
			-- set theForecast to Weather_Display & " " & Current_Temp
			set theForecast to ""
			set theForecast to WeatherIcon & " " & Current_Temp & " (Daylight: " & Daily_Temp & ")"
			
			return theForecast
			
		end try
		
		
	end tell
	
end getWeather

You could add some logging to the script to figure out whether it’s actually executed (see log message command) and also disable the automatic/scheduled sync temporarily.

That’s the sort of thing I was after, thanks.

Any tips on what information to include in the log message – what will support need to know?

Cheers!

Logging at the beginning/end should be sufficient, the result is shown in Windows > Log and includes the time.

Thanks, Christian.

I’ll report the results tomorrow.…

An update on this: since reporting the problem, I’ve tried getting this to work as suggested (including turning automatic sync off overnight, and putting log details just after on performReminder and just before end performReminder.

The problem still remains:

a) If I set the reminder to run at a specific time the next day, it never activates the template at all (the logging messages are not triggered). This is the case whether the computer is on when the reminder is due, or off.

b) The script is triggered every time if I set it manually to a time in the future (i.e. it triggers at that new time). The logging messages are displayed.

When it fails to trigger, there is no sign anywhere I can see that anything has happened at all.

However, this morning, when the computer and DT3 were running and the reminder was due at 08:00, this message appeared at 08:08:

Screenshot 2022-07-22 at 15.12.59

(The messages are 08:36 and 08:36 are when I got bored with waiting and triggered the reminder manually at 08:35 by setting the alert time to 08:36.)

Could the CKErrorDomain 3 error somehow be related, even though it’s six minutes after the due time?

So far, I don’t seen that I’m any further forward. I suppose I could try taking out the internet calls to get the weather and headlines (see the script above), but does anyone have any other suggestions?

Many thanks

The CloudKit error should have no bearing on this at all.

I didn’t think it was, but I’d rather you told me that :slight_smile: !

Any ideas what could be happening, Jim?

Thanks!

Are you able to reproduce this after booting in safe mode? Do you use other reminders or smart rules which execute scripts?

I’ve not tried it in Safe Mode, but I’ll try to reminder to set it up tonight to see if the script is triggered in the morning.

As far as I can tell, I’m not running any scripts as reminders or rules apart from this one.

Cheers.

I continue to have the same problem as @brookter. it does not seem to be related to the type of event the reminder triggers though (e.g. in my case the reminder is supposed to display an alert). at random times the reminder ends up getting triggered erratically after all, but not periodically (although it is configured for a daily trigger)

in other words if I can help with the debug, I’d be happy to…

2 Likes

Would be good to know if there are other reminders or smart rules using scripts and whether the computer is awake & DEVONthink running when the reminder is supposed to happen. Thanks!

alright, so here we go:

I have five items with reminders, four of which are spupposed to trigger once a month and one supposed to trigger daily, however none of them is using a script (all 5 are supposed to display alerts).

I have five smart rules, two of which trigger scripts:

  • one is called “Tag Annotation Files”, making sure annotations are tagged the same as their parent item.
  • the other one is a clean up script after importing from evernote, which jim had posted on the forum a while ago. I am not pointing the smart rule to any specific database or group though as I had it run amok before (the smart rule is shown as red in the sidebar).

finally the machine is running most of the time, so the daily reminder (supposed to trigger at 9:00am) sometimes would find a sleeping machine, but mostly one running / being awake…

oh and one more: like the OP I am observing the phenomenon that putting a reminder into the immediate future, e.g. two or three minutes from now, it does get triggered, however it won’t tomorrow (when configured as daily)…

Is any of the rules scheduled periodically or On Reminder? Finally, a screenshot of one of the reminders would be useful, thanks.

the “tag annotation file” smart rule is triggered on creation, while the (inactive) “clean evernote imports” smart rule is triggered on demand, so no, neither of the smart rules is triggered periodically on on reminder.

I have attached a screenshot from the daily reminder (it’s actually supposed to trigger at 10am). I hope this is what you were looking for…

Please choose Help > Report Bug while pressing the Alt modifier key and send the result to cgrunenberg - at - devon-technologies.com - thanks! Maybe there’s a hint in the logs.