The org roam capture template I rely upon to capture bibliographic notes creates a new file with an org heading, and places all relevant PROPERTIES in a drawer right below that heading, including an ID property. However, org-roam-capture appears to be set so that it always creates a file-level ID property, which results in an annoying and unnecessary proliferation of IDs. Here’s how a captured bibliographic note looks:
:PROPERTIES:
:ID: 1DFCA536-6F58-4A8B-9E08-E7E580C706AD
:END:
#+title: Once we can see them, it’s too late
* Once we can see them, it’s too late
:PROPERTIES:
:ROAM_REFS: @Aaronson2021OnceWeCan
:URL: https://www.scottaaronson.com/blog/?p=5253
:NOTER_DOCUMENT: ~/Zotero/storage/MSBKIDU3/Aaronson2021OnceWeCan.pdf
:NOTER_PAGE:
:ID: 70650C2F-B388-4EB9-B7EB-C3D3476A9E6C
:END:
As far as I can tell, there is no user option to change this behavior. The best I was able to do, with my extremely limited Elisp skills, is to tweak the org-roam-capture- function so that it does not insert a new ID value. But org-roam-capture still creates a file-level PROPERTIES drawer, with an ID key but no corresponding value, i.e.
:PROPERTIES:
:ID:
:END:
#+title: Once we can see them, it’s too late
I would appreciate any guidance on how to change org-roam-capture- or other relevant functions so as to prevent org-roam-capture from creating this drawer altogether.
(Note that initially org-roam-capture was also inserting a ROAM_REFS property under the file-level drawer, but I solved this by setting org-roam-capture-new-node-hook to nil. See also related discussion here and here)
Hi, thanks. Yes, I am aware that org roam requires IDs to identify its nodes—I just don’t want the file itself, as opposed to the headings it contains, to be treated as a node.
Concerning using org-capture rather than org-roam-capture, the capture template is not invoked manually, but is rather triggered when certain at-point actions are selected using the citar, embark and org-roam-bibtex packages. I don’t think this behavior could be easily replicated with an org-capture template.
I have ventured in this domain in the past as well and from what I saw, it would be rather hard to remove this behaviour. You need to either use org-capture or live with the fact that this is the behaviour of org-roam-capture unfortunately.
Check if the point is in the file property drawer, if so delete the ID property; leave it unchanged if point is in a headline (I think the point should be 1 if in the file property drawer, so the check should be trivial)
org-delete-property removes the entire property drawer when deleting the last remaining property, so you could have a clean Org file.
I don’t know how we can add a headline node; how do you do your capture to the headline of a file?
I do the following for my Md-roam to avoid Org-roam adding an Org-ID to the top of the file.
My previous suggestion might be simpler to implement. I don’t use headline nodes, so you would need to adjust the code. This adds advice and then uses a hook to clean up the advice – yes, a bit convoluted but this is a technique Org-roam uses in some cases.
After some experimentation, the following function and hook worked.
(defun gb/org-roam-dailies-capture-remove-id ()
"When capturing a dailies note, remove the ID generated at the parent heading, such as '2024-11-11 Monday'."
(when (org-roam-dailies--daily-note-p)
(push-mark (point))
(org-up-heading-safe)
(org-delete-property "ID")
(pop-to-mark-command)))
(add-hook 'org-capture-before-finalize-hook #'gb/org-roam-dailies-capture-remove-id)