0

I'd like to create a capture template that automatically schedules the date for the upcoming Friday (if today is a Tuesday, Wednesday, Thursday) or for the upcoming Tuesday (if today is a Friday, Saturday, Sunday, or Monday).

Any ideas are much appreciated.

2

Another way to do this is to determine the closest day of the week after today and send it to the org-read-date function.

(defun schedule-next-tuesday-or-friday ()
  (let* ((dow (format-time-string "%a" (current-time)))
         (future-dow (pcase dow
                       ((or "Sat" "Sun" "Mon") "Tue")
                       (_ "Fri"))))
    (format-time-string (car org-time-stamp-formats)
                        (org-read-date nil t future-dow))))

In the template add:

\nSCHEDULED: %(schedule-next-tuesday-or-friday)

The %(sexp) is evaluated and replaced with the result. See org-capture-templates for more information.

  • Very nice. And the solution. Using the org functions. – RichieHH Feb 13 at 11:46
  • Works like a charm! Thanks – SaMeji Feb 16 at 14:53
1

Here's an interesting solution to the "next Tuesday" issue. Note that it uses gnu date function.

your next schedule date-time:

(defun schedule-next-friday-or-tuesday(&optional ti)
  (setq dowt (string-to-number (format-time-string "%w" (if ti ti (current-time)))))
  ;;(setq dowt 2)
  (setq human-time (if(and (>= dowt 2) (<= dowt 4))
                       "next Friday"
                     "next Tuesday"))

  (parse-time-string (with-temp-buffer
                       (call-process "env" nil t nil "LC_ALL=C" "LANGUAGE=" "date" "-d" human-time)
                       (or (bobp) (delete-backward-char 1))
                       (buffer-string))))

(schedule-next-friday-or-tuesday)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.