Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using screen on OS X. I have two bind commands:

bind ( eval "writebuf" "exec sh -c 'pbcopy < /tmp/screen-exchange'" 
bind ) eval "exec sh -c 'pbpaste > /tmp/screen-exchange'" "readbuf" 

The first one takes what is in the copy buffer and sends it to pbcopy. pbcopy is a program that takes an input and writes it to the system clipboard. This command works.

The second one is suppose to write pbpaste ( from the system clipboard ) to the screen-exchange file and then read that with readbuf. This command doesn't work. I have to enter the bound key , ctrl-a ), twice for it to work. I assume I am missing something simple. Any help would be great.

Note: If I just do the pbpaste > /tmp/screen-exchange and then in screen do ctrl-a <, it works. So I think the pbpaste command is correct, there is just something that I am missing in the bind. Any help would be great.

EDIT: I'm still looking for a complete solution for this to be bound to one key. In the meantime, I can use the following bind and key strokes:

bind ) eval "exec sh -c 'pbpaste > /tmp/screen-exchange'" 

Then use

ctrl-a )
ctrl-a <

What is happening is that I'm writing my pbpaste to the screen-exchange file and then manually executing the readbuf command. As I said, I would still like a way to do this in one command. Any help would be great.

share|improve this question
how about combining the two strings and using a semicolon to delineate commands? – Just Jake Mar 29 '11 at 21:30

You might want to look at adding the following lines in your .screenrc file. If you don't have a .screenrc file you can create one in your home directory.

Add the following to your .screenrc file

shell -$SHELL

This may help you're problem I had a similar issue where my alias's from my .bash_profile were not working in screen and this fixed it. Hope it helps!

Also you may want to add startup_message off to the file while you're at it. :)

share|improve this answer

This problem got me annoyed. I just can't find a real working solution. So here's what's going on for the future problem solvers and a hack to make it work with one screen command.

The problem lies in that apparently screen eval does not wait for exec process to finish before running rest of the eval options. Same thing happens if you're fast enough with keyboard (e.g. when using registers).

So here's my hack.

setenv varfile "exec sh -c 'pbpaste > /tmp/screen-exchange'"
register r "^a:eval \$varfile^M^a:readbuf"
bind ) process r

So what it does is that it processes $varfile env and waits for user to press enter to run readbuf. So as long as you "wait" long enough for pbpasto to finish before pressing enter. You'll get what you want.

Env varfile is just for legibility.

share|improve this answer

My solution is to make commands be shell commands and sequence them with && instead of making them screen commands and sequencing with eval. As Manwe pointed out, eval doesn't work too well because it doesn't wait for one command to finish before starting the next. The screen command readbuf becomes the shell command screen -X readbuf.

So for your mac setup I would try the following:

bind ) exec sh -c "pbpaste > /tmp/screen-exchange && screen -X readbuf"

I haven't tested the above, but the working version for xwindows in my .screenrc is the following:

bind < exec sh -c "xsel -nbo > /tmp/screen-exchange && screen -X readbuf"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.