A quick one today - I’ve been using org-attach
quite a bit recently - typically to attach documents to denote
notes. What annoyed me however was that the default org-attach
directory location was not very helpful.
The below code allows for a few favourites to be specified that you can select before going through the normal org-attach
process.
This reddit post is the initial source of the below:
(defun TJ/org-attach (file-dir)
"Function to select from a range of predetermined folders for org-attach, using number inputs."
(interactive
(let* ((folders '("~/Folder1/ " "~/Folder2/" "~/Folder3/"))
(choices (mapcar (lambda (i) (format "%d: %s" (1+ i) (nth i folders)))
(number-sequence 0 (1- (length folders)))))
(choice-string (mapconcat 'identity choices "\n"))
(selection (read-char (format "Select a folder (1-%d):\n%s\n" (length folders) choice-string))))
(list (nth (1- (- selection ?0)) folders)))) ;; Convert the selection to an index
(let ((default-directory file-dir))
(org-attach)))
Here we define a function and this pulls a list of directories that you can select - specified as a list in line 4. Essentially, adding a favourites to org-attach
. I’m sure there are more elegant ways but this seems to work for my flow.
Running M-x TJ/org-attach
1 will launch a mini buffer where, using the number keys, you select which folder you want org-attach to use.
Do let me know if you have other ways of achieving similar.
-
I follow the approch of using
TJ/function-name
in my own defined functions - you can change this to something that works for you. ↩︎