2

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?

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

1 Answer 1

5

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) pclip.connect('owner-change',pcallBack) Gtk.main() 
1
  • 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! Commented Oct 24, 2017 at 14:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.