From mboxrd@z Thu Jan 1 00:00:00 1970 From: Myles English Subject: capture, attach, link files from web Date: Mon, 07 Oct 2013 12:49:58 +0100 Message-ID: <87wqlpuwpl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT9KH-0006qr-0W for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 07:50:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VT9K6-0001D1-9B for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 07:50:12 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:55524) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT9K5-00016b-RO for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 07:50:01 -0400 Received: by mail-wi0-f181.google.com with SMTP id ex4so4667825wid.14 for ; Mon, 07 Oct 2013 04:50:00 -0700 (PDT) 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" 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. 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