Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
pbcopy & pbpaste for Emacs
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx))

Hey, I found this from a Google search, was exactly what I needed. Thanks!


the-kenny commented Feb 9, 2012

Nice to hear! I'll check these days if Emacs 24 provides a better way of doing this.

One problem with this piece of code is encoding. It sometimes messes up unicode and I'm too lazy to fix this. Please let me hear if you find something better.

So I decided to try out tmux. It's great, except that I couldn't get it to work with Emacs. For some reason, C-y was not yanking like it is supposed to. After much debugging, I finally traced it back to this code that I had copied into my init.el. If I comment this out, C-y works in Emacs under tmux. I don't know exactly what the problem is; perhaps something related to the encoding issue you mentioned. Anyway, just an FYI for the next guy.

suvash commented Aug 14, 2013

Thanks a lot for this. I've been using Emacs 24.3.1 and it works flawlessly (so far). Also works inside a tmux window/pane. Cheers !

ZOMG Thank you so much for this!

Thanks a lot! 👍

tonini commented Nov 11, 2014

This is just great! :D


(setq interprogram-paste-function 'copy-from-osx))

There is one ) too much.

It works like a charm, thanks!

subhashb commented Jun 5, 2016

Worked right off the bat! 👍

Found this from Google search. Exactly what I wanted. Very nice indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment