4

I'm trying to leverage the power of org capture templates. There are a few tasks I know I will be scheduling on particular dates of the month. Setting their schedule and deadline in the capture template automatically would be quiet cool, however I'm unable to get to a decent solution.

Consider this example: year and month-name are variables I have initialized via setq (is it an acceptable way to do this?)

** TODO pay salaries 
   %(org-schedule 0 (format "%s %s 1 9am" year month-name))

However when this is evaluated, what I get in the file looks like this:

** TODO pay salaries 
    Scheduled to <2019-09-01 Sun 09:00>

Besides constructing the scheduled and deadline strings manually, is there any other way to achieve this?

  • 1
    Type `C-h v` aka `M-x describe-variable` and look up `org-capture-templates`. I then used isearch to search for the word "prompt" and found several mentions including "... prompt for date ...". Perhaps one of those options described in the doc-string of the above-mentioned variable suits your needs. – lawlist Sep 08 '19 at 16:33

2 Answers2

1

This seems to do the required trick. Found the jk-org-insert-time-stamp function here: https://emacs.stackexchange.com/a/27323/20123 .


* PROJ %(progn
(defun jk-org-insert-time-stamp (time-string)
  (interactive "sTime: ")
  (let ((default-time (apply 'encode-time (decode-time))))
    (org-insert-time-stamp
     (apply 'encode-time (org-read-date-analyze time-string default-time default-time)) t nil)))

(setq my-date (org-read-date nil t nil "Day 1 of month under purview?"))
(setq month-str (format-time-string "%m" my-date))
(setq month (string-to-number month-str))
(setq month-name (format-time-string "%b" my-date))
(setq year (format-time-string "%Y" my-date))
(setq lastday (calendar-last-day-of-month month year))
(setq day7 (parse-time-string (format "%s-%s-07" year month)))

(setq-local my-day1 (format-time-string "%Y-%m-01" my-date))
(format-time-string "%Y %b" my-date)

(concat " " month-name year))
%?
:LOGBOOK:
- Added: %U
:END:
** TODO pay salaries
   SCHEDULED: %(jk-org-insert-time-stamp  (format "%s %s 31 9am" year month-name))
   DEADLINE: %(jk-org-insert-time-stamp   (format "%s %s 31 11pm" year month-name))

If there is a better way to do this I would like to know. Needless to say, I was just able to stitch something up that works with my limited understanding of lisp.

1

I usually add %^{SCHEDULED}p to my org-capture template. But first it prompts for a SCHEDULED value which is useless and I leave it empty, and finally it prompts for a date and adds a SCHEDULED property to the task: SCHEDULED: <2019-11-06 Ср>.

Evgeny Mikhaylov
  • 179
  • 1
  • 14