My org-attach config, only place files go (paste / drag / download), with names I can actually read
My notes had two image piles: org-download threw everything into one folder, and org-attach had files called WechatIMG7604.jpg or some 64-char hash. Every time I added a file I had to think about where it should go. Got tired of it.
Now anything that enters an Org buffer becomes an attachment of the current heading and gets a link inserted. The nice part is how little it took, because everything already ends up in org-attach-attach:
(setq org-yank-dnd-method 'attach
org-yank-image-save-method 'attach
org-download-method 'attach)
Then one :around advice on org-attach-attach does the rest:
- junk names (hashes, IMG_1234, Screenshot…) become 20261010-083713-heading-title.png; names that already mean something are left alone
- files are moved instead of copied, so ~/Downloads doesn't fill up with leftovers
s-v pastes an image as an attachment if the clipboard has one, otherwise it's a normal yank. This was the annoying bit. "Clipboard has an image" isn't enough: browsers put the URL next to the image, and spreadsheets put a rendered picture next to the cells you copied. I ended up with "image + a single line that looks like a URL or image filename = image, anything else = text". Works for the apps I use, probably not for all of them.
There's also a transient on C-c C-a (attach newest download, rename and fix the links, Quick Look, reveal in Finder).
Full file: gist.github.com
Caveats: the clipboard part is macOS only (needs pngpaste), and since it moves files, don't point it at a folder you want to keep intact.
How do you all tell "image" from "text" on paste? Curious if there's a better rule.
9 points
Mentions
My org-attach config, only place files go (paste / drag / download), with names I can actually read My notes had two image piles: org-download threw everything into one folder, and org-attach had files called WechatIMG7604.jpg or some 64-char hash. Every time I added a file I had to think about where it should go. Got tired of it. Now anything that enters an Org buffer becomes an attachment of the current heading and gets a link inserted. The nice part is how little it took, because everything already ends up in org-attach-attach: (setq org-yank-dnd-method 'attach org-yank-image-save-method 'attach org-download-method 'attach) Then one :around advice on org-attach-attach does the rest: - junk names (hashes, IMG_1234, Screenshot…) become 20261010-083713-heading-title.png; names that already mean something are left alone - files are moved instead of copied, so ~/Downloads doesn't fill up with leftovers s-v pastes an image as an attachment if the clipboard has one, otherwise it's a normal yank. This was the annoying bit. "Clipboard has an image" isn't enough: browsers put the URL next to the image, and spreadsheets put a rendered picture next to the cells you copied. I ended up with "image + a single line that looks like a URL or image filename = image, anything else = text". Works for the apps I use, probably not for all of them. There's also a transient on C-c C-a (attach newest download, rename and fix the links, Quick Look, reveal in Finder). Full file: gist.github.com Caveats: the clipboard part is macOS only (needs pngpaste), and since it moves files, don't point it at a folder you want to keep intact. How do you all tell "image" from "text" on paste? Curious if there's a better rule.