From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleh Subject: Re: capture, attach, link files from web Date: Mon, 7 Oct 2013 15:08:50 +0200 Message-ID: References: <87wqlpuwpl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c33fd077d0f204e8265acd Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTAYR-0002b1-Cp for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 09:09:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTAYP-00010I-BS for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 09:08:55 -0400 Received: from mail-wg0-x235.google.com ([2a00:1450:400c:c00::235]:33616) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTAYP-000102-0X for emacs-orgmode@gnu.org; Mon, 07 Oct 2013 09:08:53 -0400 Received: by mail-wg0-f53.google.com with SMTP id x12so7219793wgg.20 for ; Mon, 07 Oct 2013 06:08:51 -0700 (PDT) In-Reply-To: <87wqlpuwpl.fsf@gmail.com> 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: Myles English Cc: "emacs-orgmode@gnu.org" --001a11c33fd077d0f204e8265acd Content-Type: text/plain; charset=ISO-8859-1 Hi Myles, I counter your tip with my own on capturing pdfs. Maybe you'll find some of this stuff useful for your case. My capture template captures a pdf file that I have to read. It works for: 1. A pdf file in doc-view mode. 2. Any dired buffer with point on a pdf file. What it does: 1. Create a new TODO item under gtd.org/Projects/Scientific Articles 2. The item title is "Read blah-blah by Foo", if the pdf name has proper format, otherwise it's just "Read blah-blah". 3. The pdf is attached to the TODO item. 4. A note is added with the capture time. Here's the code: (setq org.d "~/Dropbox/org/") (require 'org-attach) (require 'org-capture) (defun org-process-current-pdf () (let* ((buffer (org-capture-get :buffer)) (buffer-mode (with-current-buffer buffer major-mode)) (filename (org-capture-get :original-file))) (when (file-directory-p filename) (with-current-buffer (org-capture-get :original-buffer) (setq filename (dired-get-filename)))) (when (string= (file-name-extension filename) "pdf") (let ((org-attach-directory (concat org.d "data/")) (name (file-name-sans-extension (file-name-nondirectory filename)))) (org-attach-attach filename nil 'cp) (if (string-match "\\[\\(.*\\)\\] \\(.*\\)(\\(.*\\))" name) (format "\"%s\" by %s" (match-string 2 name) (match-string 1 name)) name))))) (add-to-list 'org-capture-templates '("p" "Pdf article" entry (file+olp (concat org.d "gtd.org") "Projects" "Scientific Articles") "* TODO Read %(org-process-current-pdf)\nAdded: %U %i\n %?\n")) regards, Oleh On Mon, Oct 7, 2013 at 1:49 PM, Myles English wrote: > > 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 > > --001a11c33fd077d0f204e8265acd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Myles,

I counter your tip with my ow= n on capturing pdfs.
Maybe you'll find some of this stuff use= ful for your case.

My capture template captures a = pdf file that I have to read.
It works for:
1. A pdf file in doc-view mode.
2. A= ny dired buffer with point on a pdf file.

What it = does:
1. Create a new TODO item under gtd.org/Projects/Scientific Articles
2. The item title is "Read blah-blah by Foo", if the pdf nam= e has
=A0 =A0 proper format, otherwise it's just "Read b= lah-blah".
3. The pdf is attached to the TODO item.
4. A note is added with the capture time.

Here'= ;s the code:

(setq org.d "~/Dropbox/org/= ")
(require 'org-attach)
(require 'org-cap= ture)
(defun org-process-current-pdf ()
=A0 (let* ((buffer (org-ca= pture-get :buffer))
=A0 =A0 =A0 =A0 =A0(buffer-mode (with-current= -buffer buffer major-mode))
=A0 =A0 =A0 =A0 =A0(filename (org-cap= ture-get :original-file)))
=A0 =A0 (when (file-directory-p filename)
=A0 =A0 =A0 (with-= current-buffer (org-capture-get :original-buffer)
=A0 =A0 =A0 =A0= (setq filename (dired-get-filename))))
=A0 =A0 (when (string=3D = (file-name-extension filename) "pdf")
=A0 =A0 =A0 (let ((org-attach-directory (concat org.d "data/"= ;))
=A0 =A0 =A0 =A0 =A0 =A0 (name (file-name-sans-extension
=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(file-name-nondirectory filenam= e))))
=A0 =A0 =A0 =A0 (org-attach-attach filename nil 'cp)
=A0 =A0 =A0 =A0 (if (string-match "\\[\\(.*\\)\\] \\(.*\\)(\\(.*\= \))" name)
=A0 =A0 =A0 =A0 =A0 =A0 (format "\"%s\&= quot; by %s"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (match-= string 2 name)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (match-str= ing 1 name))
=A0 =A0 =A0 =A0 =A0 name)))))

(add-to-list &#= 39;org-capture-templates
=A0 =A0 =A0 =A0 =A0 =A0 =A0'("p= " "Pdf article" entry (file+olp (concat org.d "gtd.org") "Projects" "Scientifi= c Articles")
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"* TODO Read %(org-process-current= -pdf)\nAdded: %U %i\n =A0%?\n"))

regard= s,
Oleh









On Mon, Oct 7, 2013 at 1:49 PM,= Myles English <mylesenglish@gmail.com> wrote:

Hello,

Just thought I would share something I find useful. =A0What the code below<= br> 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)
=A0 "Download a file, attach it to our heading, insert a link" =A0 (interactive "*sAttach and link to url: \n")
=A0 (let ((tmpdir (expand-file-name (getenv "TMPDIR")))
=A0 =A0 =A0 =A0 (fname (file-name-nondirectory lnk)))
=A0 =A0 (progn (message (concat "Downloading " lnk " to &quo= t; tmpdir "/" fname))
=A0 =A0 =A0 =A0 =A0 =A0(call-process "wget" nil '("*Mess= ages*" t) nil "-P"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0tmpdir "-d" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0lnk)
=A0 =A0 =A0 =A0 =A0 =A0(org-attach-attach (concat tmpdir "/" fnam= e) nil 'mv)
=A0 =A0 =A0 =A0 =A0 =A0(insert (concat "[[att:" fname "]]&qu= ot;)))))

(define-key global-map "\C-cs" 'my-attach-and-link-web-file)<= br> #+that_was_elisp

Myles


--001a11c33fd077d0f204e8265acd--