• Possible to be notified when the clipboard contents changes?

    From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.windows.x on Mon Feb 23 13:13:17 2026
    From Newsgroup: comp.windows.x

    I have a shell script that needs to do something if certain text shows up
    on the X clipboard. It currently uses "xsel" to access the clipboard, but needs to do polling in a loop, like this:\

    while :; do clip="$(xsel)"; [[ "$clip" =~ something ]] && do_something;sleep 3;done

    This works OK, but it'd be better if it didn't need to poll. Is there any event-ish way to do this?

    I looked at a few of the clipboard-related utilities available - xcutsel
    and xclipboard - but didn't find anything interesting.

    BTW, if there is a way to do this that involves C programming (writing/compiling something with X lib calls), I am open to that.
    --
    If Jeb is Charlie Brown kicking a football-pulled-away, Mitt is a '50s housewife with a black eye who insists to her friends the roast wasn't
    dry.
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Eli the Bearded@*@eli.users.panix.com to comp.windows.x on Mon Feb 23 21:08:35 2026
    From Newsgroup: comp.windows.x

    In comp.windows.x, Winston <wbe@UBEBLOCK.psr.com.invalid> wrote:
    gazelle@shell.xmission.com (Kenny McCormack) writes:
    I have a shell script that needs to do something if certain text shows up
    on the X clipboard. It currently uses "xsel" to access the clipboard, but >> needs to do polling in a loop, like this:\
    ...
    I don't know for sure, but, for compiled code, have a look at:
    man 3 XInternAtom
    man 3 XGetWindowProperty
    and PropertyNotify events
    for the atoms 0(CUT_BUFFER0) and XA_PRIMARY.

    The xev I have installed does not show PropertyNotify for those atoms.
    Hacking xev to to catch them would be a good start to writing a C
    program that monitors the clipboard.

    Elijah
    ------
    has hacked xev for his own purposes in the past
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.windows.x on Mon Feb 23 21:19:17 2026
    From Newsgroup: comp.windows.x

    In article <eli$2602231607@qaz.wtf>,
    Eli the Bearded <*@eli.users.panix.com> wrote:
    In comp.windows.x, Winston <wbe@UBEBLOCK.psr.com.invalid> wrote:
    gazelle@shell.xmission.com (Kenny McCormack) writes:
    I have a shell script that needs to do something if certain text shows up >>> on the X clipboard. It currently uses "xsel" to access the clipboard, but >>> needs to do polling in a loop, like this:\
    ...
    I don't know for sure, but, for compiled code, have a look at:
    man 3 XInternAtom
    man 3 XGetWindowProperty
    and PropertyNotify events
    for the atoms 0(CUT_BUFFER0) and XA_PRIMARY.

    The xev I have installed does not show PropertyNotify for those atoms. >Hacking xev to to catch them would be a good start to writing a C
    program that monitors the clipboard.

    xev is a good idea. I've used it already for some other projects.

    I'll look into it for this purpose at some point.
    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/BestCLCPostEver
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Winston@wbe@UBEBLOCK.psr.com.invalid to comp.windows.x on Mon Feb 23 17:17:49 2026
    From Newsgroup: comp.windows.x

    gazelle@shell.xmission.com (Kenny McCormack) writes:
    I have a shell script that needs to do something if certain text
    shows up on the X clipboard. It currently uses "xsel" to access the
    clipboard, but needs to do polling in a loop, ...

    I replied (in part):
    I don't know for sure, but, for compiled code, have a look at:
    man 3 XInternAtom
    man 3 XGetWindowProperty
    and PropertyNotify events
    for the atoms 0(CUT_BUFFER0) and XA_PRIMARY.

    Eli the Bearded <*@eli.users.panix.com> replied (in part):
    The xev I have installed does not show PropertyNotify for those atoms.

    Just tried something: Running "xev -root | fgrep Property" in an xterm,
    then mouse selecting a word in any xterm window, reports a
    PropertyNewValue event for CUT_BUFFER0.

    However, no event was reported when the selection was lost, nor did
    deletion in Emacs (which sets something typically used by "paste")
    report an event, so this solution looks incomplete (it probably needs
    to test XA_PRIMARY).
    -WBE
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.windows.x on Mon Mar 2 22:02:04 2026
    From Newsgroup: comp.windows.x

    In article <ydecmbqf3m.fsf@UBEblock.psr.com>,
    Winston <wbe@UBEBLOCK.psr.com.invalid> wrote:
    ...
    Just tried something: Running "xev -root | fgrep Property" in an xterm,
    then mouse selecting a word in any xterm window, reports a
    PropertyNewValue event for CUT_BUFFER0.

    However, no event was reported when the selection was lost, nor did
    deletion in Emacs (which sets something typically used by "paste")
    report an event, so this solution looks incomplete (it probably needs
    to test XA_PRIMARY).

    Just FYI:

    I was never able to get "xev" to tell me anything about the clipboard per se, so that turned out to be a dead end.

    However, I was able to achieve a pretty good solution to my overall problem
    by running: xev -id $id -event keyboard
    where $id is the window ID of my browser window.

    This works because I use the keyboard (right mouse, then c) to grab the
    URL of the current page in the browser. One doesn't use the keyboard for
    much else in the browser, so this works pretty well. After "xev" tells me
    that a key was hit in the browser, then I (i.e., the script) can fetch the clipboard with "xsel" and check to see if there is anything useful there.
    --
    There are many self-professed Christians who seem to think that because
    they believe in Jesus' sacrifice they can reject Jesus' teachings about
    how we should treat others. In this country, they show that they reject
    Jesus' teachings by voting for Republicans.
    --- Synchronet 3.21d-Linux NewsLink 1.2