Created
October 12, 2019 08:23
-
-
Save tevino/75af1361fe68801df5cb2b2a09afed13 to your computer and use it in GitHub Desktop.
Markdown daily journal template based on builtin smart template "Daily Journal" in DEVONthink 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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 and styles updated by Eric Böhnisch-Volkmann June 28, 2019 | |
Changes done by Tevin Zhang 2019-10-12 | |
- Use markdown instead of rtd | |
- Remove news | |
- Use date format specified by ISO 8601 to reduce the effort of localization | |
*) | |
property dailyGroupPath : "/Life Management/Journal/Daily/" | |
-- 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 | |
set theDay to day of theDate as string | |
if the (length of theDay) < 2 then set theDay to "0" & theDay | |
-- 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 dailyGroupPath | |
set recordName to theYear & "-" & numMonth & "-" & theDay & " " & shortWeekday | |
set myContent to "" | |
if not (exists child recordName of myGroup) then -- Create the document from scratch | |
set myRecord to create record with {name:recordName, plain text:"", type:markdown, tags:theYear & "," & theMonth} in myGroup | |
set theHeadline to "# " & theYear & "-" & numMonth & "-" & theDay & space & longWeekday | |
--Fetch the daily quote | |
set qod to my getQuote() | |
set myContent to theHeadline & return & return & qod | |
else -- Record already exists, just add new time header | |
set myRecord to child recordName in myGroup | |
end if | |
set timeHeader to "## " & ((theTime) as string) | |
set myContent to myContent & return & return & timeHeader & return & return | |
set plain text of myRecord to (plain text of myRecord & myContent) | |
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 a daily quote | |
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 & "> " & return & "> " & title of randItem | |
end if | |
end try | |
return myQuote | |
end tell | |
end getQuote |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment