From: Carlos Russo <mestre.adamastor@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: How to attach data in clipboard directly?
Date: Sat, 25 Jun 2011 11:06:35 +0100 [thread overview]
Message-ID: <iu4bvb$op5$1@dough.gmane.org> (raw)
In-Reply-To: <80pqm3499k.fsf@somewhere.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?
next prev parent reply other threads:[~2011-06-25 10:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2011-06-27 16:44 ` Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='iu4bvb$op5$1@dough.gmane.org' \
--to=mestre.adamastor@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.