From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlos Russo Subject: Re: How to attach data in clipboard directly? Date: Sat, 25 Jun 2011 11:06:35 +0100 Message-ID: References: <98495103-9583-4D34-A516-85B15DAD785F@gmail.com> <80pqm3499k.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaPoY-00068x-H6 for emacs-orgmode@gnu.org; Sat, 25 Jun 2011 06:10:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QaPoX-0006Qa-9V for emacs-orgmode@gnu.org; Sat, 25 Jun 2011 06:10:10 -0400 Received: from lo.gmane.org ([80.91.229.12]:54624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaPoW-0006PS-U1 for emacs-orgmode@gnu.org; Sat, 25 Jun 2011 06:10:09 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QaPoS-0003Q9-Mg for emacs-orgmode@gnu.org; Sat, 25 Jun 2011 12:10:04 +0200 Received: from bl14-81-21.dsl.telepac.pt ([85.247.81.21]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 25 Jun 2011 12:10:04 +0200 Received: from mestre.adamastor by bl14-81-21.dsl.telepac.pt with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 25 Jun 2011 12:10:04 +0200 In-Reply-To: <80pqm3499k.fsf@somewhere.org> 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 >> What I want is that emacs/orgmode understands the contents of the clipboard >> and creates that file for me. For instance, if it detects that the contents >> of the clipboard is an image or some sort of non-text format, emacs would >> dump the clipboard data to a file, auto-generate a filename, guessing the >> data type, and attach that file to my org-file via org-attach-attach. > > See Automatic screenshot insertion on Worg: > > http://orgmode.org/worg/org-hacks.html#sec-3-8 > > Best regards, > Seb > Thank you for your suggestion, Seb. The script "Automatic screenshot insertion" from Worg is based on "import" from Imagemagick, which operates on X buffers. I'm actually running Aquamacs in Mac OS X (10.6), so this solution doesn't work for me. Nevertheless, it's a good pointer: I was able to cook up an elisp function that calls an applescript to do the osx-dependent stuff. I suppose that X11 users could use xclip or xsel instead (did not try it, though). Here is the elisp bit: (defun org-capture-clipboard-as-png () "Save the contents of the clipboard as a time stamped unique-named .png file in the same directory as the org-buffer and insert a link to this file." (interactive) (setq filename (concat (make-temp-name (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S_")) ) ".png")) (call-process "~/.emacs.d/scripts/save_clipboard.applescript" nil nil nil filename ) (insert (concat "[[" filename "]]")) ;; (org-display-inline-images) ) and here is the applescript bit ( save_clipboard.applescript ) #!/usr/bin/osascript on run argv set fn to item 1 of argv # Check if Clipboard is empty set blnIsClipboardEmpty to false try set dataClipboard to the clipboard on error strErrorMessage number intErrorNumber if (intErrorNumber is -25131) then set blnIsClipboardEmpty to true end if end try # Try to save clipboard contentsas png if blnIsClipboardEmpty is false then set d to the clipboard as «class PNGf» set fid to open for access fn with write permission write d to fid close access fid end if end run Sure, this is far from perfect. I would like these scripts to - guess data type that is in clipboard and save the data with the correct extension - make the elisp script aware of the file extension - somehow feed this to org-attach, in order to have all of the git-attach goodies. but this is beyond my skills at the moment... Any hints?