Journal/Diary creation

Some time ago I found a script (I don’t remember where, perhaps here, perhaps googling), to automatically create a new document inside DT with a fixed header containing current date, geolocation and other useful information to generate a template to be used as diary entry…

However, I cannot find it anymore… Any help will be appreciated.

The only one I could find here is this one:

Wow!!

Thanks, but that is not what I was looking for and I think cannot be adapted to what I want (apart of the fact that apple script and me are moral enemies -I have no idea about that :blush: ).

What I want is to have a macro or whatever that will create a Formatted Note/Rich Text with some auto generated part like date and time creation, location (if possible) and weather status. More or less like a replacement of Day One or Journey…

I’m almost sure I read about that somewhere…

I will try to do something later and be here.

Might this be it?

Note, the linked script has several hardcoded web references that are now broken, 6 years since it was created.

Way more I wanted!!! :smiley: :smiley: :smiley: :smiley:

Man, it is complete!

After removing the forecast weather, that now requires a auth token, and other stuff related to date/time in European format, I’m getting a popup window in DT with this error:

No puede obtenerse every text of think window 1.

It is in “Spanglish”. A translation could be “Cannot be obtained every text of think window 1”. It generates a RTF file in the right place but completely empty.

I’m still investigating why this happens, but any help will be appreciated.

Modified script is:

(*
		Chuck Lane October 2, 2013
		If the group heirarchy 'Journal/Year/Year-Month' doesn't exist, it's created.
		 Creates file in the form of 'month_day_year_weekday' such as '10_13_2013_Sun'.
		 A header with the date, holidays/birthdays, a random quote, and the current weather and time.
		If the file already exists , then no new file will be created and a new header will be added to the existing file consisting of the current weather and time.
		I store the compiled script titled "Journal___Shift-F1" (There are 3 underscores in the name) in the DTPO /Scripts/Toolbar folder so that I can add it to Devonthink's toolbar. You can also call the script by pressing the 'Shift Fn F1' keys.
		The application 'Calendar' will be launched if it isn't already running.
		Calendar is the biggest slowdown, you can get rid of that part of the code if you don't care about holidays or birthdays being displayed.
		Change the property holidayCalendar to the one you're subscribed to.
		You may have to change the delay value after launching Calendar for your
		own computer.
		You may use this script or any part of it in any way you see fit.
		I've added korm's DayOne script. You must have the DayOne CLI installed for this to work. Set the property 'dayOneFlag' to true if you have DayOne.
	
*)
property blueColor : {0, 0, 30000}
property headerColor : {40000, 20000, 0}
property blackColor : {0, 0, 0}
property dateColor : {30000, 30000, 30000}
property holidayCalendar : "US Holidays"
property birthdayCalendar : "Birthdays"
property j_Prefix : ""
property dayOneFlag : false -- Set this flag to true if you have installed DayOne and the DayOne CLI

global theDate, targetPath, numHeadlines

set theDate to current date
set numHeadlines to 4

-- We need Calendar running so we can check holidays and birthdays
if not (get running of application "Calendar") then
	launch application "Calendar"
	delay 0.5 -- wait for Calendar
end if
(*
on getWeather()
	--Go here to get the parameters for different locations: http://developer.yahoo.com/weather/#req
	tell application id "com.devon-technologies.thinkpro2"
		try
			set theWeather to download markup from "http://weather.yahooapis.com/forecastrss?w=12770553&u=f"
			set des to description of item 1 of (get items of feed theWeather)
			set theText to do shell script "echo " & quoted form of des & " | textutil -stdin -stdout -format html -convert txt -encoding UTF-8" --Convert the html to plain text
			set picURL to (texts (offset of "h" in des) thru (offset of "f" in des)) of des
			set theForecast to paragraph 3 of theText
			
			--Create a folder in the user's documents folder (if it doesn't already exist)
			set folderName to "zTempFolder"
			set folderPath to get (path to documents folder from user domain) as text
			set filePath to (folderPath & folderName & ":")
			tell application "Finder"
				if not (exists folder filePath) then
					make new folder at folder folderPath with properties {name:folderName}
				end if
			end tell
			
			--Download and save the weather icon to the folder we created
			set targetPath to filePath & "TempImage.jpeg"
			do shell script "curl " & picURL & " -o " & quoted form of POSIX path of targetPath
		end try
		return "TEST"
	end tell
end getWeather
*)
on getQuote()
	tell application id "com.devon-technologies.thinkpro2"
		try
			set myQuote to ""
			set getSource to download markup from "feed://feeds.feedburner.com/quotationspage/qotd"
			set getFeed to get items of feed getSource
			if items of getFeed is not {} then
				set randItem to some item of getFeed
				set myQuote to description of randItem & return & "=    " & title of randItem & "    =" & return
			end if
		end try
		return myQuote
	end tell
end getQuote

--Get the news headlines
on getNews()
	set myNews to {}
	tell application id "com.devon-technologies.thinkpro2"
		try
			set getNewsSource to download markup from "feed://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
			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

on getHoliday() -- Also gets birthdays
	tell application "Calendar"
		try
			set holidayList to {}
			set mydate to theDate
			set time of mydate to 0 -- set time to midnight
			tell calendar holidayCalendar
				set allHolidays to get events whose start date is equal to mydate
				if allHolidays is not {} then
					repeat with theItem in allHolidays
						set end of holidayList to summary of theItem
					end repeat
				end if
			end tell
			tell calendar birthdayCalendar
				set birthdayList to {}
				set allBirthdays to get every event
				if allBirthdays is not {} then
					repeat with theItem in allBirthdays
						set myStart to start date of theItem
						set year of myStart to year of mydate
						if myStart is equal to mydate then
							set end of birthdayList to summary of theItem
						end if
					end repeat
				end if
			end tell
		end try
		return {holidayList, birthdayList}
	end tell
end getHoliday

-- This code snippet is compliments of korm
on makeJournalEntry(j_Content)
	set new_JournalEntry to "echo " & (quoted form of j_Content) & " | /usr/local/bin/dayone  new"
	do shell script new_JournalEntry
end makeJournalEntry

-- TIME FORMAT: Strip out the seconds but keep the AM/PM indicator
set theTime to time string of theDate
if character 5 of theTime is ":" then
	set theTime to (characters 1 through 4 of theTime) & (characters 8 through 10 of theTime) as string
end if

-- MONTH FORMAT
set theMonth to month of theDate as string
set numMonth to (month of theDate as integer) as string
if the (length of numMonth) < 2 then set numMonth to "0" & numMonth

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

-- WEEKDAY FORMAT
set longWeekday to weekday of theDate as string
set shortWeekday to characters 1 thru 3 of longWeekday

-- YEAR FORMAT
set theYear to year of theDate as string
set theYearMonth to theYear & "-" & numMonth

set recordName to numMonth & "_" & theDay & "_" & theYear & "_" & shortWeekday
set newHeading to "El tiempo aquí" & "   " & theTime & return
set mainHeading to theMonth & space & shortDay & daySuffix & "," & space & longWeekday & return

tell application id "com.devon-technologies.thinkpro2"
	try
		activate
		set myGroup to create location "/Journal/" & "/" & theYear & "/" & theYearMonth
		set label of every child in myGroup to 0
		set root of think window 1 to myGroup
		if not (exists child recordName of myGroup) then
			set myRecord to create record with {name:recordName, rich text:"", type:rtfd, label:5, tags:theYear} in myGroup
			open tab for record myRecord in think window 1
			close first tab in think window 1
			
			show progress indicator "I'll be out to play computer shortly..."
			
			tell text of think window 1
				make paragraph at beginning with properties {alignment:center, font:"Zapfino", size:18, color:dateColor} with data mainHeading
				bold first paragraph
				unbold last character
				set properties of last character to {font:"Avenir", size:14}
				
				--Show any holidays and/or birthdays
				set allEvents to my getHoliday()
				repeat with eachList in allEvents
					if eachList is not {} then
						set theCount to 0
						repeat with theItems in eachList
							set theCount to theCount + 1
							if theCount = 1 then
								set the last character to the last character & theItems
							else
								set the last character to the last character & "     " & theItems
							end if
						end repeat
						set the last character to the last character & return
						set color of last paragraph to blueColor
					end if
				end repeat
				if item 2 of allEvents is not {} then set last character to last character & return
				set color of last character to blackColor
				
				--Show the daily quote
				set myQuote to my getQuote()
				set the last character to the last character & myQuote & return
				set alignment of last character to left
				
				--Show specified number of news headlines
				set myNews to my getNews()
				set the last character to the last character & "HEADLINES:" & return
				bold last paragraph
				unbold last character
				repeat with i from 1 to (count of items of myNews) by 2
					set the last character to the last character & item i of myNews & return
					set the URL of the last paragraph to item (i + 1) of myNews
				end repeat
			end tell
			
			--This code is compliments of korm. It adds a link to a new DayOne note.
			if dayOneFlag is true then
				set d_Default to return & return & return
				set j_Header to "## " & j_Prefix & recordName & return & return
				set d_Prompt to "Notation about " & recordName as string
				set j_Note to "Click link to see note in Devonthink"
				set j_Link to "[See document](" & (the reference URL of myRecord as string) & ")"
				set j_Content to j_Header & j_Note & return & return & j_Link
				my makeJournalEntry(j_Content)
			end if
			
		else -- Record already exists, just add new weather/time header
			set myRecord to child recordName in myGroup
			set label of myRecord to 5
			open tab for record myRecord in think window 1
			close first tab in think window 1
		end if
		
		tell text of think window 1
			set the last character to the last character & return & return
			
			--Insert the weather graphic that we saved
			set theFile to targetPath as alias
			make new attachment at end of paragraphs with properties {file name:theFile}
			
			make new paragraph at end with data (newHeading)
			set properties of last paragraph to {font:"Avenir", size:16, alignment:left, superscript:4, color:headerColor}
			italicize last paragraph
			set properties of last character to {font:"Avenir", size:16, alignment:left, superscript:0, color:blackColor}
			set last character to last character & "■ "
		end tell
		
		hide progress indicator
		
	on error errMsg number errNum
		hide progress indicator
		display alert (localized string "An error occured when adding the note. ") & errMsg
	end try
	
end tell

Here’s an updated & simplified version for DEVONthink 3 (e.g. the weather forecast didn’t work anymore). This script also demonstrates the advanced rich text scripting of version 3 - it’s not necessary anymore to open windows or tabs to script this, the rich text of records can be directly scripted.

(*
	Based on script by Chuck Lane October 2, 2013
	Updated and optimized for DEVONthink 3 by Christian Grunenberg April 30, 2019
*)

property headerColor : {40000, 20000, 0}
property blackColor : {0, 0, 0}
property dateColor : {30000, 30000, 30000}
property numHeadlines : 4

set theDate to current date

-- TIME FORMAT: Strip out the seconds but keep the AM/PM indicator
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

-- MONTH FORMAT
set theMonth to month of theDate as string
set numMonth to (month of theDate as integer) as string
if the (length of numMonth) < 2 then set numMonth to "0" & numMonth

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

-- WEEKDAY FORMAT
set longWeekday to weekday of theDate as string
set shortWeekday to characters 1 thru 3 of longWeekday

-- YEAR FORMAT
set theYear to year of theDate as string

tell application id "DNtp"
	try
		activate
		set myGroup to create location "/Journal/" & "/" & theYear & "/" & numMonth
		set recordName to theYear & "-" & numMonth & "-" & theDay & " " & shortWeekday
		if not (exists child recordName of myGroup) then
			set myRecord to create record with {name:recordName, rich text:"", type:rtfd, tags:theYear & "," & theMonth} in myGroup
			
			tell text of myRecord
				make paragraph at beginning with properties {alignment:center, font:"Zapfino", size:18, color:dateColor} with data (theMonth & space & shortDay & daySuffix & "," & space & longWeekday & return)
				bold first paragraph
				unbold last character
				set properties of last character to {font:"Avenir", size:14}
				
				--Show the daily quote
				set myQuote to my getQuote()
				set the last character to the last character & myQuote & return
				set alignment of last character to left
				
				--Show specified number of news headlines
				set myNews to my getNews()
				set the last character to the last character & "HEADLINES:" & return
				bold last paragraph
				unbold last character
				repeat with i from 1 to (count of items of myNews) by 2
					set the last character to the last character & item i of myNews & return
					set the URL of the last paragraph to item (i + 1) of myNews
				end repeat
			end tell
			
		else -- Record already exists, just add new weather/time header
			set myRecord to child recordName in myGroup
		end if
		
		tell text of myRecord
			set the last character to the last character & return & return
			make new paragraph at end with data ((theTime & return) as string)
			set properties of last paragraph to {font:"Avenir", size:16, alignment:left, superscript:4, color:headerColor}
			italicize last paragraph
			set properties of last character to {font:"Avenir", size:16, alignment:left, superscript:0, color:blackColor}
			set last character to last character & "■ "
		end tell
	on error errMsg number errNum
		display alert (localized string "An error occured when adding the note. ") & errMsg
	end try
end tell

on getQuote()
	tell application id "DNtp"
		try
			set myQuote to ""
			set getSource to download markup from "feed://feeds.feedburner.com/quotationspage/qotd"
			set getFeed to get items of feed getSource
			if items of getFeed is not {} then
				set randItem to some item of getFeed
				set myQuote to description of randItem & return & "=    " & title of randItem & "    =" & return
			end if
		end try
		return myQuote
	end tell
end getQuote

--Get the news headlines
on getNews()
	set myNews to {}
	tell application id "DNtp"
		try
			set getNewsSource to download markup from "feed://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
			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
3 Likes

It is simply incredible!!! If you run twice the same day, it adds the new date to the same file!!!

I’m enthusiastic with DT3!!!

1 Like

Tried this nice script but over here it creates a new record for each run. What am I missing?

What’s the name of the created entry? Is the display of file extensions en/disabled?

Name is 2019-05-10 Fri.rtf (extension enabled as you can see). Tried it again and now I’ve got 3 records with name 2019-05-10 Fri.rtf

Offtopic: I’m using DEVONthink 3 and was confronted with this alert at the first day (it’s a database for daily automated WebArchives).

2019-05-01_04-44-16
Rebuilt it but the next day the alert came back. Since then I just clicked “ignore” after launch. Also DEVONthink 3 crashed sometimes when the Keyboard Maestro macro started to download. Just checked and there was no successful download for one week.

Please choose Help > Report Bug while pressing the Alt key so that we can have a look at the crash logs. Thanks!

Done!

I’m trying to set the Journal location in a specific database but I don’t find the right command. Script editor says that “create location” has an optional option called “in”, but seems I’m doing something wrong as does not matter how I modify the script, the entry is generated in the active database.

What I’m trying to do is something like this:

set myGroup to create location "/Journal/" & "/" & theYear & "/" & numMonth in "RFOG"

When original line was:

set myGroup to create location "/Journal/" & "/" & theYear & "/" & numMonth

I’m no expert and I don’t know if this is the cause of your issue, but doesn’t your code set myGroup to

"/Journal//theYear/nuMont"

ie. two // after Journal? (I’ve a vague feeling the // resets the path back to its root – it does in Emacs, anyway)

That way not only does not write in the right place but even sets the path to just the text and not the variable content. Think that

"/Journal/" & "/" & theYear & "/" & numMonth

ends in

"/Journal/2019/May"

I know my string wasn’t what you wanted for the variable substitution (it was only an example) it’s the repeated / / after Journal which looks odd. Do you want the actual path to read

/Journal//2019/May

(ie with 2 // after Journal, which is what your snippet does, I think) or

/Journal/2019/May

(only 1 / after Journal)?

But I’ll leave the experts to take that further…

Oh, now I understand. You are right, but AFAIK those errors are normally understood by the file path processors.

I’ve done some modified changes to the script to:

  • Insert the journal in a specific database
  • Read my favorites from Inoreader instead of NYT news
  • If there are not enough favorites in Inoreader, the number is adjusted accordingly
  • If Inoreader favorites is not available or is zero, NYT is used instead.
  • Assign all variables at start position to ease change the wanted values.

I think I will improve this better in a future. My next try could be get a random photo from my photo library or get the Astronomy image of the day or similar.

This is the modified script: Add Journal entry
(Sorry, don’t know how to beautify the text here).

(Sorry, don’t know how to beautify the text here).

If you’re referring to showing the code with syntax highlighting, use triple backticks at the beginning and end and paste the code in between.