Help modifying Daily Journal template

I tried to modify the daily journal template and I seemed to have missed a step.

I opened the main.scpt template and deleted the bits with the daily quote, changed the local headlines to Google News and a local TV news station. The script compiled successfully.

However, when I run the template, the old daily journal template runs – not the new one. It seems like there’s some kind of pointer in the template package that continues to point to the old script.

What am I missing? I am modifying the main.scpt file – is there another file I need to modify as well?

Thanks!

The Daily Journal template doesn’t point to an external template. It creates a record each time it runs.

set myRecord to create record with {name:recordName, content:theContent, type:markdown, tags:theYear & "," & theMonth} in myGroup

It seems like there’s some kind of pointer in the template package that continues to point to the old script.

Did you modify the main.scpt in the template package?

And do you see the same behavior after quitting and relaunching DEVONthink?


Here’s my modified template: Daily Journal Modified.templatescriptd.zip (24.5 KB) yielding…

Yes, I did modify main.scpt and quit and restarted DevonThink.

The main part of my (attempted) changes to the script were to get rid of the daily quote and use different RSS feeds for news. However, when I run the template I seem to be getting the same result as if I had not changed the script at all. I see the quote and the NY Times headlines. I also tried to rename everything to “daily note” instead of “journal,” because I like calling it a daily note.

I’m using the markdown version of the script.

Here’s the script as I altered it – what am I doing wrong here?

(*
Based on script by Chuck Lane October 2, 2013
Daily journal script
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 headerColor : {40000, 20000, 0}
property blackColor : {0, 0, 0}
property dateColor : {30000, 30000, 30000}
property numHeadlines : 4

– 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

– Retrieve the user’s locale so that we can e.g. get localized quotes and headlines
set theLocale to user locale of (get system info)
if the (length of theLocale > 2) then
set theLocale to (characters 1 through 2 of theLocale) as string
end if

– 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 “”
if theLocale is not “de” then
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
else
set daySuffix to “th”
end if
end if

– Format the year
set theYear to year of theDate as string

– Format month and weekday names (localized)
if theLocale is “de” then
set theMonth to word 3 of (theDate as text)
set longWeekday to word 1 of (theDate as string)
else
set theMonth to month of theDate as string
set longWeekday to weekday of theDate as string
end if
set shortWeekday to characters 1 thru 3 of longWeekday

tell application id “DNtp”
try
activate
set myGroup to create location “/Daily notesl/” & “/” & theYear & “/” & numMonth
set recordName to theYear & “-” & numMonth & “-” & theDay & " " & shortWeekday
set myRecords to children of myGroup whose name is recordName and type is markdown
if ((count of myRecords) is 0) then – Create the document from scratch
if my theLocale is “de” then
set theHeadline to (longWeekday & “,” & space & shortDay & “.” & space & theMonth)
else
set theHeadline to (theMonth & space & shortDay & daySuffix & “,” & space & longWeekday)
end if

		set myQuote to my getQuote()
		set myNews to my getNews()
		set theContent to "# " & theHeadline & return & "<i>" & myQuote & "</i>" & return & return & "# Headlines" & return & return
		
		repeat with i from 1 to (count of items of myNews) by 2
			set theContent to theContent & "[" & item i of myNews & "]"
			set theContent to theContent & "(" & item (i + 1) of myNews & ")   " & return
		end repeat
		
		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
	
	set theContent to plain text of myRecord
	set plain text of myRecord to theContent & return & return & "## " & theTime & return & "- "
	
	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

–Get the news headlines
on getNews()
set myNews to {}
tell application id “DNtp”
try
if my theLocale is “de” then
set getNewsSource to download markup from “feed://www.tagesschau.de/xml/rss2”
else
set getNewsSource to download markup from “https://news.google.com/news/rss/?gl=US&ned=us&hl=en
end if
set getNewsFeed to items 1 thru numHeadlines of (get items of feed getNewsSource)
repeat with theItems in getNewsFeed
set end of myNews to title of theItems
set end of myNews to link of theItems
end repeat
end try
return myNews
end tell
end getNews

–Get the news headlines
on getNewsLocal()
set myNewsLocal to {}
tell application id “DNtp”
try
if my theLocale is “de” then
set getNewsSource to download markup from “feed://www.tagesschau.de/xml/rss2”
else
set getNewsSource to download markup from “http://fox5sandiego.com/feed/
end if
set getNewsFeed to items 1 thru numHeadlines of (get items of feed getNewsSource)
repeat with theItems in getNewsFeed
set end of myNews to title of theItems
set end of myNews to link of theItems
end repeat
end try
return myNews
end tell
end getNewsLocal

Hi @Mitch_Wagner, did you ever find a resolution. I’m running into the same issue and hope to find the answer.

Did you try the modified template I posted?

Thanks. I did. The issue is that changes to the main.scpt file are not recognized when I run the template in app. I don’t know if I need to recompile a template (if that’s even the right word). Perhaps of note: in finder main.scpt indicates today as the last modified day, but for the .dttemplate package it indicates December 5, 2019.

As an aside, is there a way to delete a template that you imported to DTPO?

My temporary fix is to make a Keyboard Maestro macro so that when I hit CMD-CNTRL-OPT-SHFT-J I run the script to create the new file. This is working great for now and may actually be my preferred method in the future. Just trying to figure out the template thing.

Did you quit and relaunch DEVONthink after making changes?

As an aside, is there a way to delete a template that you imported to DTPO?

You can just delete them from the ~/Library/Application Support/DEVONthink 3/Templates.noindex folder.

Well, I feel like a dummy. I did quit and relaunch DEVONthink after making changes. BUT–and this is the dummy part–I was making changes to the main.scpt file in the DEVONthink.app package! and not in the application support folder. Woah. Talk about a bad idea.

So, for any other person looking to amend the templates, I suggest you not make the same mistake I did (thought there were no lasting ramifications.) That is edit the templates in ~/Library/Application Support/DEVONthink 3/ and not in the application package.

Thanks again @BLUEFROG for your incredibly quick help!

You’re very welcome :slight_smile:

I’ve been using the Daily Journal template–which is excellent–but it saves to my inbox. Is there a way to move the “Journal” group to one of my databases?
Thanks.

Only by customizing the template as it needs to know the location of the journal.

The Journal group and its files should be created in the current database.

Ahh, that’s why I had Journal folders in multiple places. Thank you!

You’re welcome :slight_smile:

I never was able to solve this problem. I’m now trying again.

I want to eliminate the quote, weather and news headlines. I just want an empty file with timestamps as # headers.

Here’s what I tried:

I copied the original template.

I modified main.scpt to remove everything I could find in it that seemed to refer to a quote and headlines. Here is the result:

(*
	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 headerColor : {40000, 20000, 0}
property blackColor : {0, 0, 0}
property dateColor : {30000, 30000, 30000}
property numHeadlines : 4

-- 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 ""
if theLocale is not "de" then
	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
	else
		set daySuffix to "th"
	end if
end if

-- Format the year
set theYear to year of theDate as string

-- Format month and weekday names (localized)
set shortWeekday to characters 1 thru 3 of longWeekday

tell application id "DNtp"
	try
		activate
		set myGroup to create location "/Journal/" & "/" & theYear & "/" & numMonth
		set recordName to theYear & "-" & numMonth & "-" & theDay & " " & shortWeekday
		set myRecords to children of myGroup whose name is recordName and type is markdown
		if ((count of myRecords) is 0) then -- Create the document from scratch
			
			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
		
		set theContent to plain text of myRecord
		set plain text of myRecord to theContent & return & return & "## " & theTime & return & "- "
		
		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

After making the modifications, I closed and restarted DevonThink, and then run the modified, duplicate template.

Expected outcome:

A markdown file that just shows a # header with timestamp–no quote, no headline.

Here’s what I get:

A markdown file that starts with a quote and five headlines from the NY Times.

In other words, even after I modify the script it still seems to run the original script, as if I had made no modifications at all.

How do I fix this?

Bluefrog, I did not run your script modification because it produces an RFT file, not an RTD, and has a quote at the top, which I do not want.

UPDATE:

I removed blank lines from the end of the script, compiled, and saved. I also tried closing DevonThink, modifying the script, adding or removing a blank line from the end, and then restarting DevonThink–this is an alternative to modifying the script with DT open, and then closing and restarting DT.

And now I’ve made progress! The script does absolutely nothing! It does not create groups or documents! So, progress I guess? Yay?

It does nothing because there are errors in the code you posted.

Here is a modified and simplified version…
Daily Journal - Simple Markdown.templatescriptd.zip (35.7 KB)

1 Like

I think I’ve solved this problem, by running the script from inside the Script Editor, which seems to have kicked something loose and registered the updates.

Before doing that, I restarted DevonThink and rebooted the Mac. These actions may have also helped with the solution.

See the topic preceding this message:

1 Like