Org-id - moving to timestamps

I have been thinking for sometime, why use pseudo random numbers as uids? This is actually not the truest way to create an unique number- although each digit is pseudo random, there is a small but not zero chance that in infinite time, there will be atleast 1 conflict.

Time is actually the best way to create unique ids - also as a bonus; it will also be automatically apparent when the node was made and is actually a very good way to merge with your physical notes.

To use time stamps as unique ids I use

(setq org-id-method 'ts                                                         ; use time stamps as uuids
      org-id-ts-format "%Y/%m/%d.%H:%M:%S")

Those of you who use org-attach, it must have also occurred to you that the way it keeps those files - are in default- alien to common sense. But most importantly org-attach would create a problem in this situation because we are using / and we cannot have / in folder names - right ? So one can remove the “/” from the format and everything will be alright.

But I wish to keep it, because I want it to be better human readable, so I would also make some changes to org-attach, firstly, if we are even taking the pain to configure org-attach just dump the entire folder naming scheme; I have all my inputs to org files coming from a directory called resources, and I want to create two subdirectories; one with the file name and another with the heading to which it is attached (fits like hand in gloves with org-download :smile: ). We can use the following code to achieve this

;; Org Attach Configuration

;; Set the base directory for org-attach
(setq org-attach-id-dir "resources")

;; Define a custom function for generating attachment paths
(defun custom/org-attach-id-dir (id)
  "Dynamically generate the org-attach-id-dir based on buffer.
  This function constructs the directory structure for Org attachments
  using the buffer name and heading string."
  (let (
        (headline-string (nth 4 (org-heading-components)))
    (concat (buffer-name) "/" headline-string)))

;;  use the above function to resolve attachment directory determination
(setq org-attach-id-to-path-function-list '(custom/org-attach-id-dir))

;; Maintain relative paths for portability
(setq org-attach-dir-relative t)

;; Automatically tag attachment headlines
(setq org-attach-auto-tag "attached")

Will use this and let know if I fall into other problems by doing this.

I have been using a time stamp format (my custom) almost as soon as I started using Org-roam, I think, in 2020 when it came out.

I haven’t had any issues really.

The way I do will be part of my write-up for my use of tags that you wished to see. It’s taken me some time and I have been writing it (incrementally and now pushing it to the end!) I hope I can publish it soon :slight_smile:

1 Like