(* Based on script by Chuck Lane October 2, 2013 Updated and optimized for DEVONthink 3 by Christian Grunenberg April 30, 2019 Some changes by RFOG to set news to Inoreader Favorites and put the journal in a specific database, June 7, 2019 June 8, 2019: Some bug fixing when Inoreader has no favs. *) property headerColor : {40000, 20000, 0} property blackColor : {0, 0, 0} property dateColor : {30000, 30000, 30000} property numHeadlines : 10 property quoteOfDayUrl : "feed://feeds.feedburner.com/quotationspage/qotd" property inoreaderUrl : "feed://www.inoreader.com/stream/user/1005968576/tag/user-favorites" property genericNewsUrl : "feed://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml" property desiredDatabase : "~/Databases/RFOG.dtBase2" 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 theDatabase to open database desiredDatabase set myGroup to create location "/Journal/" & theYear & "/" & numMonth in theDatabase 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 getDevonthinkFavorites() set myNewsSize to count of myNews if (myNewsSize = 0) then set myNews to my getNews() end if 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 getDevonthinkFavorites() set myNews to {} tell application id "DNtp" try set getNewsSource to download markup from inoreaderUrl set feedItems to get items of feed getNewsSource set feedSize to count of feedItems if (feedSize < numHeadlines) then set localNumHeadlines to feedSize else set localNumHeadlines to numHeadlines end if if (numHeadlines = 0) then --display alert numHeadlines return myNews end if set getNewsFeed to items 1 thru localNumHeadlines of feedItems 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 getDevonthinkFavorites on getQuote() tell application id "DNtp" try set myQuote to "" set getSource to download markup from quoteOfDayUrl 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 genericNewsUrl set feedItems to get items of feed getNewsSource set feedSize to count of feedItems if (feedSize < numHeadlines) then set localNumHeadlines to feedSize else set localNumHeadlines to numHeadlines end if if (numHeadlines = 0) then return myNews end if --display alert numHeadlines set getNewsFeed to items 1 thru localNumHeadlines of feedItems 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