The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 25,288β€…    Votes:  4β€…
Tags: scripts   python   clipboard  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

URL: https://askubuntu.com/q/1144385
Title: Why is this python script running in background consuming 100 % CPU?
ID: /2019/05/18/Why-is-this-python-script-running-in-background-consuming-100-_-CPU_
Created: May 18, 2019
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


I was intrigued by this project so wrote a bash script for those more comfortable in that environment:

#!/bin/bash

xclip -o -sel clip > /tmp/LastClip

while true ; do 

    xclip -o -sel clip > /tmp/NewClip
    diff -q /tmp/LastClip /tmp/NewClip > /tmp/DiffClip
    if [[ -s /tmp/DiffClip ]] ; then
        cat /tmp/NewClip    # For testing dump to screen instead of printing
        cp -a /tmp/NewClip /tmp/LastClip
    fi
    sleep 1.0
    
done

It does require Xorg’s xclip package:

sudo apt install xclip

It’s dumping clipboard contents to screen using cat command. If you want hard copy instead replace cat with lp and specify your printer name, orientation and possibly β€œfit to page” option.

You will see a bit of lag to screen because I choose sleep 1.0 which would be unnoticeable with a printer and still faster than people can highlight text and use Ctrl+C.

If you copy the exact same highlighted text to the clipboard it doesn’t trigger a difference. One letter more or less will trigger a response.

⇧ How to restart X Window Server from command line and be able to login again afterwards? How do I suppress GtkDialog warnings in zenity and yad using Bash redirection in a script?  β‡©