org-download
org-download copied to clipboard
Syntax to create subdirectories for each org file: (setq-default org-download-image-dir "./img/?")
What would be the syntax to create separate directories withint an /img directory for each orgmode buffer? This would allow a cleaner organization of images (not having all images in one directory).
This creates a directory /img where all images would go:
(setq-default org-download-image-dir "./img")
Duplicate of #46
A slightly better function that creates separate folders for each org file.
(defun my-org-download-method (link)
(let ((filename
(file-name-nondirectory
(car (url-path-and-query
(url-generic-parse-url link)))))
(dirname (concat "./img/" (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))))
(setq org-download-image-dir dirname)
(make-directory dirname t)
(expand-file-name filename dirname)))
(setq org-download-method 'my-org-download-method)
Thanks! Haven't tried it yet. What names would the directories within img/ have?
Thanks! Haven't tried it yet. What names would the directories within img/ have?
The current org buffer file name where you're inserting the image.
Thank you! So at the moment in my init I have these two lines regarding org-download:
(setq org-download-method 'directory)
(setq-default org-download-image-dir "./img")
Shall I replace both with just
(setq org-download-method 'my-org-download-method)
I suppose the line (setq-default org-download-image-dir "./img") is not necessary?
Thank you! So at the moment in my init I have these two lines regarding org-download:
(setq org-download-method 'directory) (setq-default org-download-image-dir "./img")Shall I replace both with just
(setq org-download-method 'my-org-download-method)
You would include the function defintion for my-org-download-method as well before it.
I suppose the line
(setq-default org-download-image-dir "./img")is not necessary?
Yes, not necessary.
I just tried this but it doesn't create subdirectories within /img eg., /img/NAMEOFBUGGER/. It creates new directories with name /imgNAMEOFBUFFER.
I just tried this but it doesn't create subdirectories within /img eg.,
/img/NAMEOFBUGGER/. It creates new directories with name/imgNAMEOFBUFFER.
Ensure that there is a trailing slash after "./img/" in this line
(dirname (concat "./img/" (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))))
Yes! My bad! Thanks again!
Hi, I encountered an issue with this: now my screenshots are named screenshot.png.
So if I paste a screenshot using org-download in my org buffer untitled.org, it creates a folder /img/untitled/screenshot.png.
So when I paste a second screenshot... it tells me there is already a screenshot.png.
Before it used to name every screenshot prepending the date plus time: 20220418-142539_screenshot.png.
How could your code be interfering with this naming?
Thanks!
Any advice on this? Thanks!
@pirattidasan Thank you.
Tried you code. It works. However, the display of image size changes.
In the default setting where the org-download-method is attach, the dragged-in image is displayed in a very proper size that matches the buffer font and width. If I use your code and change this method, the image size is displayed very large.
I'm using doom emacs. I'm not sure whether the image size is defined in doom or by the org-attach itself. Some idea about this?
Hi, I encountered an issue with this: now my screenshots are named
screenshot.png. So if I paste a screenshot usingorg-downloadin my org buffer untitled.org, it creates a folder/img/untitled/screenshot.png.So when I paste a second screenshot... it tells me there is already a
screenshot.png.Before it used to name every screenshot prepending the date plus time:
20220418-142539_screenshot.png. How could your code be interfering with this naming? Thanks!
org-download-file-format-function should help.
(defun my-org-download-method (link)
(let ((filename
(file-name-nondirectory
(car (url-path-and-query
(url-generic-parse-url link)))))
(dirname (concat "./org-download-imgs/" (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))))
(setq org-download-image-dir dirname)
(make-directory dirname t)
(expand-file-name (funcall org-download-file-format-function filename) dirname)))
(setq org-download-method 'my-org-download-method)
doesn't work
(defun my-org-download-method (link)
(let ((dirname (concat (file-name-sans-extension (buffer-file-name)) "-images")))
(setq org-download-image-dir dirname)
(make-directory dirname t)
))
(setq org-download-method 'my-org-download-method)