I would like to be able to use a smart template to:
- in a specific group and always this same group in the same dB
- ask for a new itemName
- create a new group with that itemName
- create a new markdown file with itemName
- populate it with some basics (TOC, date, itemName, etc)
- add some tags
- run the existing script “Add as to do to reminders” on the new markdown file.
I started with the Daily Journal smart template, stripped out the date localization sections and have tried to modify it to my own ends but got a little into the weeds.
The ask-for-input text is working and I can create a new markdown doc with the right stuff but I can’t get it to create the group it should go into and to put it into that group.
Also haven’t got around to figuring out the reminder section.
Anyone with a machete care to help me hack my way back to the beaten path?
Thanks.
(*
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
*)
-- 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
-- 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 theResponse to display dialog "What's the name of the new To-Do Item?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
-- {button returned:"Continue", text returned:" "}
set newToDoName to text returned of theResponse
tell application id "DNtp"
try
activate
set groupToDo to get record with uuid "265FFD7A-B6F0-4ADA-B9BF-51C0269E53D1"
set myGroup to create location groupToDo & "/" & newToDoName
set theContent to "{{TOC}} " & return & "# " & newToDoName & return
set myRecord to create record with {name:newToDoName, content:theContent, type:markdown, tags:"TO-DO List" & "," & "CGT2"} in myGroup
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