Emmanuel Goldstein
Emmanuel Goldstein

Reputation: 363

How to create a function to lauch org-capture with a selected template?

Let's say my capture template is bound to 't':

(defun my/captureTemplate ()
(interactive)
(org-capture "r")

This won't work as it will show me the whole list of potential templates to choose from. Thanks!

Upvotes: 1

Views: 504

Answers (1)

NickD
NickD

Reputation: 6422

You should check the doc string of org-capture withC-h f org-capture RET to see how to call it from lisp:

(org-capture &optional GOTO KEYS)

...

ELisp programs can set KEYS to a string associated with a template in ‘org-capture-templates’. In this case, interactive selection will be bypassed.

So try

(defun my/captureTemplate ()
   (interactive)
   (org-capture nil "t"))

In other words, call it with nil as the GOTO argument and "t" as the KEYS argument. I assumed that you meant to use the t template as you mentioned at the beginning, although you have r in your function and I also added a closing paren to close the defun.

Upvotes: 2

Related Questions