;; evaluate this to remove all IDs that are neither: a target, has attachment(s) nor timestamp (synced with caldav) ;; assume everything is in `~/org', including archived files ;; require `rg', `jq' and `awk' (let* ((default-directory (expand-file-name "~/org")) (ids (-> (shell-command-to-string "rg -a -g '*.org*' --json '^:ID:\s*([A-Za-z00-9\-])+\s*$' | jq -r '.data.submatches | select(.) | .[].match.text' | awk '{ print $2 }' | sort") (string-trim) (split-string "\n"))) (targets (-> (shell-command-to-string (format "rg -a -g '*.org*' --json '\\[id:(%s)]' | jq -r '.data.submatches | select(.) | .[].match.text[4:-1]' | sort" (string-join ids "|"))) (string-trim) (split-string "\n"))) (not-targets (seq-difference ids targets))) (save-excursion (seq-each #'(lambda (id) (condition-case nil (progn (org-id-goto id) (unless (or (org-entry-get nil "SCHEDULED") (org-entry-get nil "DEADLINE") (org-entry-get nil "TIMESTAMP") (member "ATTACH" (org-get-tags nil t))) ;; (message "DELETE %s" id) (org-delete-property "ID"))) (error (message "FALSE POSITIVE %s" id)))) not-targets)))