I would like to use org-protocol to capture to an existing org file if one already exists. I am using a function to generate the file name interactively for the org file to be captured to:

(defun my/generate-org-note-name ()
  (setq my-org-note--name (read-string "Name: "))
  (setq my-org-note--time (format-time-string "%Y%m%d%H%M%S"))
  (expand-file-name (format "%s-%s.org" my-org-note--time my-org-note--name) (concat org-directory "links/")))

So is there a way to make Emacs search for some property like "URL" in my org directory and if it finds one, it appends the capture to it otherwise if it doesn't exist it creates a new file? As it stands now, if I use the org-capture-extension, it runs the function to ask me for a file name and creates a new file.

My relevant capture templates are as follows:

("p" "Protocol" plain (file my/generate-org-note-name)
("L" "Protocol Link" plain (file my/generate-org-note-name)
         "%(format \"#+title: %s\n#+date: %U\n\" my-org-note--name my-org-note--time)#+author: %^{Author}\n#+filetags: :Web_Link:%^{Tags}\nLink: [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n\n* %?\n")


I realise that org-roam-protocol exists. Since I use org-roam I'm also open to any suggestions that use org-roam as well

  • What does this have to do with org-protocol? This seems to concern org-capture only.
    – NickD
    Commented Apr 13, 2022 at 15:34
  • The templates are the ones that I use with the org capture extension which uses org-protocol
    – sab hoque
    Commented Apr 14, 2022 at 1:29
  • Are you talking about this?
    – NickD
    Commented Apr 14, 2022 at 1:52
  • yes, that is what I am talking about
    – sab hoque
    Commented Apr 14, 2022 at 8:48
  • IIUC you are trying to make your interactive file selection non-interactive when you find some property in an unspecified place, presumably because it's a pain to select something in the browser to save and then have to go to Emacs to specify where it is going to be saved. So why have the interacitve function at all and not save to a fixed file?
    – NickD
    Commented Apr 14, 2022 at 10:20


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.