Create a gist now

Instantly share code, notes, and snippets.

Embed
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))
@speedarius

This comment has been minimized.

Show comment
Hide comment
@speedarius

speedarius Feb 9, 2012

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

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

@the-kenny

This comment has been minimized.

Show comment
Hide comment
@the-kenny

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

Owner

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.

@speedarius

This comment has been minimized.

Show comment
Hide comment
@speedarius

speedarius Nov 10, 2012

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.

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

This comment has been minimized.

Show comment
Hide comment
@suvash

suvash 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 !

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 !

@mdesjardins

This comment has been minimized.

Show comment
Hide comment
@mdesjardins

mdesjardins Oct 21, 2013

ZOMG Thank you so much for this!

ZOMG Thank you so much for this!

@scudelletti

This comment has been minimized.

Show comment
Hide comment
@scudelletti

scudelletti Aug 5, 2014

Thanks a lot! 👍

Thanks a lot! 👍

@tonini

This comment has been minimized.

Show comment
Hide comment
@tonini

tonini Nov 11, 2014

This is just great! :D

typo:

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

There is one ) too much.

tonini commented Nov 11, 2014

This is just great! :D

typo:

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

There is one ) too much.

@galderz

This comment has been minimized.

Show comment
Hide comment
@jslu0418

This comment has been minimized.

Show comment
Hide comment
@jslu0418

jslu0418 May 15, 2016

It works like a charm, thanks!

It works like a charm, thanks!

@subhashb

This comment has been minimized.

Show comment
Hide comment
@subhashb

subhashb Jun 5, 2016

Worked right off the bat! 👍

subhashb commented Jun 5, 2016

Worked right off the bat! 👍

@gudmunduregill

This comment has been minimized.

Show comment
Hide comment
@gudmunduregill

gudmunduregill Sep 7, 2016

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

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