Hello!
I want to automate the creation of a new **denote** journal file each day. I want to verify if it already exists, if not create it and then find the previous journal, check if there are TODO/SCHEDULED/DEADLINE tasks and move them into the new journal.
For now I have the following:
(require 'cl-lib) ;; needed for cl-return
(defun journal-day-exists-p ( target )
"check if journal for a day already exists"
(file-expand-wildcards (concat (denote-directory) target "*_journal*.org")))
(defun find-previous-journal ()
"Find most recent journal"
(let* ((today (format-time-string "%Y%m%d"))
(all_journals (sort (directory-files "~/Dropbox/orgfiles/denotes" nil "^[0-9].*_journal.*org$") #'string>)))
(dolist (journal all_journals)
(when (string< (substring journal 0 8) today)
(cl-return journal)))))
(defun my-denote-journal ()
"Create an entry tagged 'journal' with the date as its title."
(interactive)
(let* ((today (format-time-string "%Y%m%d"))
(filename (car (journal-day-exists-p today)))
(prev (find-previous-journal)))
(if filename
(find-file filename)
(progn
(denote
(format-time-string "%A %e %B %Y") ; format like Tuesday 14 June 2022
'("journal")
nil
"~/Denotes")
(insert "* Thoughts\n\n* Ideas\n\n* Code\n\n* TASKS\n\n")))))
Now the part where I need help is in moving the Tasks, I already have the idea that I should use org-refile or org-archive, but I am not seeing how to open the previous file and get what I need from it.
Can anyone help?
​
Thank you!