From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: capture, attach, link files from web Date: Mon, 07 Oct 2013 23:55:12 +0800 Message-ID: <87siwdoz33.fsf@ericabrahamsen.net> References: <87wqlpuwpl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTD8o-0005dW-5V for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 11:54:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTD8e-0006vB-Bi for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 11:54:38 -0400 Received: from plane.gmane.org ([80.91.229.3]:57286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTD8e-0006uN-4s for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 11:54:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VTD8c-0001Rr-6X for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 17:54:26 +0200 Received: from 111.199.226.97 ([111.199.226.97]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Oct 2013 17:54:26 +0200 Received: from eric by 111.199.226.97 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Oct 2013 17:54:26 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Myles English writes: > Hello, > > Just thought I would share something I find useful. What the code below > does is: > > 1) prompts for a link to a file on the internet > 2) downloads the file > 3) attaches the file to the current subtree > 4) inserts at the current point a link to the attachment > > This is useful if (e.g.) you are scouring Google images for ideas and > want to save lots of image files. Interesting! I've done a fair amount of this, and wanted this exact sort of function, and have been too lazy to implement it myself. A couple of thoughts: Rather than sending downloaded files to $TMPDIR, it might be nice to have them just use whatever dir org-attach would have used. I use org-attach from time to time, and notice that everything ends up under ~/org/data/. I haven't actually investigated why that happens (I've got org-directory set to ~/org/), mostly because it strikes me as a fine default. When we've got that directory, setting a different TMPDIR seems unnecessary. I'll admit part of my hesitation comes from the fact that "TMPDIR" sounds like it's going to get automatically deleted at some point. I've often thought it would be nice to link to images in an org file with http: links, then at some arbitrary point in time call a hypothetical org-localize-external-resources command. That command would wget all the external resources, put them somewhere local, and switch the links to the file: type. Just a thought. Regardless, thanks for posting this. It's fun to see other people thinking in familiar directions. E > Requirements: wget, set $TMPDIR. > TODO: integrate properly with capture template > > #+here_is_some elisp > (setq org-link-abbrev-alist '(("att" . org-attach-expand-link))) > > (defun my-attach-and-link-web-file (lnk) > "Download a file, attach it to our heading, insert a link" > (interactive "*sAttach and link to url: \n") > (let ((tmpdir (expand-file-name (getenv "TMPDIR"))) > (fname (file-name-nondirectory lnk))) > (progn (message (concat "Downloading " lnk " to " tmpdir "/" fname)) > (call-process "wget" nil '("*Messages*" t) nil "-P" > tmpdir "-d" > lnk) > (org-attach-attach (concat tmpdir "/" fname) nil 'mv) > (insert (concat "[[att:" fname "]]"))))) > > (define-key global-map "\C-cs" 'my-attach-and-link-web-file) > #+that_was_elisp > > Myles