Directly open an Org roam node by id from other programs
Since I want to interconnect Org Roam notes with my Anki cards and Freeplane mindmaps, I need to create a customized link type like this roam://<org-roam-node-id>
, which can be directly opened from other programs.
-
Create an Elisp function for opening the Org Roam node by id:
(defun tjh/org-roam-open-node-by-id (id) (interactive "sNode id:") (let ((node (org-roam-node-from-id id))) (if node (org-roam-node-visit node))))
-
Create a Bash script
open-org-roam-node-link.sh
, which usesemacsclient
to evaluate the elisp code to open the node:#!/bin/bash emacsclient --eval "(let ((node (org-roam-node-from-id (substring \"$1\" 7 nil)))) (if node (org-roam-node-visit node) (message \"Node not found!\")))"
-
Create a new
desktop
file~/.local/share/applications/roam-url-handler.desktop
:[Desktop Entry] Name=Roam URL Handler Exec=/usr/local/bin/scripts/open-org-roam-node-link.sh %u Terminal=false Type=Application NoDisplay=true MimeType=x-scheme-handler/roam;
-
Register the above
desktop
file:xdg-mime default roam-url-handler.desktop x-scheme-handler/roam
-
Insert
roam://<org-roam-node-id>
links in other programs, such as Anki: