emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to attach data in clipboard directly?
@ 2011-06-24 10:21 Carlos Russo
  2011-06-24 14:03 ` Sebastien Vauban
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos Russo @ 2011-06-24 10:21 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I often need to paste fragments of pictures/images to my org file.

Typically, I manually paste the fragment to a file, and then use C-c C-a m to attach that file to my org-file.
This is rather tedious, because there are a few steps and extra programs involved, and I guess there must be a better way to do this.

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.

I'm thinking of a org-attach-clipboard sort of command, accessible via the C-c C-a (org-attach) menu.

Perhaps I'm demanding too much from emacs and org-mode, but hey,  couldn't it be done? It would be a cool feature...
More important, _hasn't_ this been done already?

Regards,
Carlos

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to attach data in clipboard directly?
  2011-06-24 10:21 How to attach data in clipboard directly? Carlos Russo
@ 2011-06-24 14:03 ` Sebastien Vauban
  2011-06-25 10:06   ` Carlos Russo
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastien Vauban @ 2011-06-24 14:03 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Carlos Russo,

Carlos Russo wrote:
> Hello,
>
> I often need to paste fragments of pictures/images to my org file.
>
> Typically, I manually paste the fragment to a file, and then use C-c C-a m
> to attach that file to my org-file. This is rather tedious, because there
> are a few steps and extra programs involved, and I guess there must be a
> better way to do this.
>
> 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.
>
> I'm thinking of a org-attach-clipboard sort of command, accessible via the
> C-c C-a (org-attach) menu.
>
> Perhaps I'm demanding too much from emacs and org-mode, but hey, couldn't it
> be done? It would be a cool feature... More important, _hasn't_ this been
> done already?

See Automatic screenshot insertion on Worg:

    http://orgmode.org/worg/org-hacks.html#sec-3-8

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to attach data in clipboard directly?
  2011-06-24 14:03 ` Sebastien Vauban
@ 2011-06-25 10:06   ` Carlos Russo
  2011-06-27 16:44     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos Russo @ 2011-06-25 10:06 UTC (permalink / raw)
  To: emacs-orgmode

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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to attach data in clipboard directly?
  2011-06-25 10:06   ` Carlos Russo
@ 2011-06-27 16:44     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2011-06-27 16:44 UTC (permalink / raw)
  To: Carlos Russo; +Cc: emacs-orgmode

Hi Carlos,

Carlos Russo <mestre.adamastor@gmail.com> writes:

> 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.

A good start, then -- could someone add this to Worg hacks?

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-27 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-24 10:21 How to attach data in clipboard directly? Carlos Russo
2011-06-24 14:03 ` Sebastien Vauban
2011-06-25 10:06   ` Carlos Russo
2011-06-27 16:44     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).