0

When using org-attach (using the standard C-c C-a a command), the default source directory (for the find-file minibuffer) is "~/Org/roam". How do I change that to a different directory, specifically "~/Downloads"?

2
  • Why do you want to do this? Are you going to create multiple attachments using files in ~/Downloads? If you only have a single file, then deleting ~/Org/roam in the minibuffer and typing ~/Downloads/... is probably the quickest and most convenient way. If you have more than one, then I would enable the dired-dwim facility and open ~/Downloads in a second window.
    – NickD
    Sep 3, 2022 at 17:36
  • 1
    Because 95% of the time I'm attaching files that I downloaded, and so I want the download folder to be the default.
    – Alan
    Sep 3, 2022 at 23:53

1 Answer 1

0

The easiest approach seems to be to temporarily set the function read-file-name to look in the target folder. This can be done with the excellent noflet package:

(defun azr/org-attach ()
  "Org-attach but looks in downloads folder first. Requires noflet."
  (interactive)
  (noflet ((read-file-name (&rest args)
                           (funcall this-fn "Select file: " "~/Downloads")))
    (org-attach)))

Or a more complicated answer using the built-in advice capabilities:

(defun azr/org-attach-read-file-name-downloads (&rest args)
  '("Select file to attach: " "~/Downloads"))

(defun azr/org-attach ()
  (interactive) 
  (advice-add 'read-file-name :filter-args 'azr/org-attach-read-file-name-downloads)
  (unwind-protect ; make sure to remove advice if user cancels org-attach
      (org-attach)
    (advice-remove 'read-file-name 'azr/org-attach-read-file-name-downloads)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.