I'm aware of xsel and xclip, ( also discussed in: https://stackoverflow.com/questions/749544/pipe-to-from-the-clipboard ), and use them often.

However, now I would like to have the primary clipboard dumped to stdout, but in "follow mode". Currently, if I try this:

$ xclip -o
Currently, if I try this:
$ xsel -o
Currently, if I try this:

... the commands exit immediately.

What I would like instead, is a behavior similar to tail -f /var/log/syslog - that is, "follow mode": tail blocks the terminal, and whenever a new line shows in the file, it dumps it to standard output.

I'd like something similar, but for whenever I make a new copy (i.e., press Ctrl-C, or Ctrl-Shift-C in terminal) - that is, whenever I change the primary clipboard contents.

Is there a command that will help me do that in bash?

  • 1
    I do similar for myself Would you be happy with a 16 line python script?
    – Tagwint
    Oct 23, 2017 at 18:52
  • Thanks @Tagwint - would be quite happy with that :)
    – sdaau
    Oct 23, 2017 at 19:18
  • Are you using desktop which supports appindicators by any chance ? Oct 24, 2017 at 17:45

1 Answer 1


OK, here's a python solution. I don't think it needs comments, it does exactly what requested, but let me know if my assumption is wrong.

#!/usr/bin/env python
import sys 
import signal
import gi
gi.require_version("Gtk", "3.0")
from   gi.repository import Gtk, Gdk 

def pcallBack(*args):
    print pclip.wait_for_text() 

if __name__ == '__main__':    
        import signal    
        signal.signal(signal.SIGINT, signal.SIG_DFL)    
        pclip = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
  • Awesome, @Tagwint, thanks so much for that! It's just that I needed the dump only when I make a copy (that is, press Ctrl-C), your script dumps every time I make a new text selection - but that is easily fixed by changing Gdk.SELECTION_PRIMARY into Gdk.SELECTION_CLIPBOARD (corrected my OP to reflect that). Thanks again - cheers!
    – sdaau
    Oct 24, 2017 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .