Example Python code, that saves text to the Linux clipboard, persistently.

There are some quirks as to how the Linux X-server clipboard works, which have been observed for some time, but which will also affect how to write a Python script / program, that saves some text to the clipboard, but with the intention that the script should exit immediately, while the copied text should remain on the clipboard.

What works against that, is the way the X11 clipboard works generally, which is, that there is no part of the actual O/S, which stores the clipboard contents. Instead, the application being copied from stores this data, and the data is not transferred until another application, or the same application, pastes it again. This has as consequence, that if the first application tries to store the data to the clipboard but then exits, and if the second application next tries to paste it, the clipboard, by first approximation, will be empty because the first application, which was holding the data, has quit.

There may exist some Linux environments in which the desktop manager takes over in a case like that, to hold a copy of the data that was Copied, but my Debian / Stretch, Plasma 5.8 computer, which I name ‘Phosphene’, fails to do so. And this is also how or why, the Plasma 5 clipboard utility, which is named ‘Klipper’, will sometimes still show that last item at the top of its clipboard history, but why that item cannot be pasted (using <Ctrl>+V), until an earlier item is selected within Klipper, and then the item of interest is selected again, so that this most-recently copied item will actually be available on the clipboard again.

In principle, ‘Klipper’ has a setting which states ‘Assure clipboard never empty’. But, long story short, that setting does not work

(Update 4/09/2019, 6h05 : )

Actually, I have learned an intricacy, of how the Plasma 5, Klipper app interacts with the X11 clipboard, and which I was not aware of before. Apparently, the actual clipboard has 3 ‘slots’: ‘Primary’, ‘Secondary’, and ‘Clipboard’. Mouse-Highlighting will cause ‘Primary’ to point to the selected text, while <Ctrl>+C Copying will cause ‘Clipboard’ to point to the selected text. After that, middle-clicking with the mouse will Paste from ‘Primary’, while <Ctrl>+V will Paste from ‘Clipboard’.

When using <Ctrl>+C, an ideally Linux-compliant application will actually leave with both clipboard targets pointing at the selection, while certain applications such as Firefox will only end up with ‘Clipboard’ pointing at the selected text.

The only real pitfall in understanding ‘Klipper’ was, the fact that while it does keep a copy of the clipboard’s contents ‘on the side’, regardless of how they were Copied, Pasting that copy directly after the application Copied from has closed, is only facilitated for middle-clicking with the mouse, not for the <Ctrl>+V -type Pasting.

However, left-clicking on one of the entries in the Klipper History will cause the ‘Clipboard’ X11 pointer to point to it, unless that just happens to be the most-recent entry.

Basically, the user community wanted an alternative to Windows, that has familiar features, and instead, the Linux developers left them a well-hidden Easter Egg. (:1)


 

I recently needed to install a Python script, which hashes a domain-name, password combination, and which has as feature the ability to save the hash-code ‘to the clipboard’, instead of just printing it out, so that the user should next be able to paste the hash-code, and in some cases do so, without the hash-code ever being displayed. This script failed to work in its original version and I needed to modify it, to get it to work the way I wanted it to work.

(Updated 4/09/2019, 15h40 … )

Continue reading Example Python code, that saves text to the Linux clipboard, persistently.

How to Bring Back those Sticky Notes!

KDE 4 and Plasma 5.x have had it as a common feature, that if we middle-click with our mouse-wheel ‘anywhere on the desktop’, a Sticky Note appears, which we don’t even need an installed application to manage. Firstly I need to explain why I was not aware of this feature before. The reason is my custom, to Lock the Widgets of my Desktops as soon as possible, after modifying them. With the widgets locked, this behaviour does not take place because the sticky note in question is an additional widget each time…

Screenshot_20190325_215803

But during a recent project, I had a desktop environment in which the widgets were unlocked all the time, so that eventually, I middle-clicked on the mouse button accidentally, and faced the popular dilemma of how to delete the sticky notes created, and eventually, of how to keep them from re-appearing. The way to delete each individual note, at least on my computers, is to hold down the left mouse-button along the inside, of the right border of the widget in question, until a side-bar pops out, that allows widgets to be moved, resized and deleted, as of Plasma 5…

Screenshot_20190325_215827

The thing to do next is, to release the left mouse-button, and to move the mouse-pointer quickly, to the red ‘X’ button that has just appeared at the bottom of the side-bar, and then to left-click that once.

To prevent the behaviour from taking place again, it’s necessary to right-click on an empty part of the desktop, so that the usual context-menu appears, and then to left-click on “Configure Desktop” (under Plasma 5). Then, one can modify the “Mouse Actions” that appear there, so that the action to middle-click the mouse-wheel, is either deleted, or no longer specifies To Paste.

So I hurriedly disabled this feature before realizing that in this one specific situation, it might actually be useful to me. The reason for that is the fact that my usual note-taking application, “Tomboy”, creates redundant icons and window-place-holders, on a desktop manager where I’d like for there to be as few window-icons as possible. Additionally, on this setup, I wouldn’t be syncing my Tomboy application, which is a main reason otherwise to be using Tomboy.

What I did next was to re-assign the function to the middle-mouse-click, To Paste, and then to hope that I had restored the original feature. But what I found instead, in the immediate term, was that middle-clicking with the mouse wheel, no longer brought back the sticky notes -creation. So the next question which raced through my mind was, ‘Have I deleted a detail in the configuration, which is difficult to restore? Does that Mouse Action require more than just To paste? Help! Help! I can’t get the nuisance back, even though I no longer think it’s a nuisance!’

BTW, This is not a question which most people ask, so there are few if any Web-pages that answer this question…

Continue reading How to Bring Back those Sticky Notes!