Logo

dev-resources.site

for different kinds of informations.

Inspecting the Clipboard (on Linux)

Published at
11/4/2021
Categories
javascript
clipboard
copy
Author
thumbone
Categories
3 categories in total
javascript
open
clipboard
open
copy
open
Author
8 person written this
thumbone
open
Inspecting the Clipboard (on Linux)

Developing a small Javascript library to support copying arbitrary HTML elements to the clipboard ready (for use in emails), I was using CopyQ to inspect the clipboard whenever I needed to. In particular I was interested in seeing the MIME parts of the copy.

Turns out that CopyQ is a little flakey with the WebAPI copy command I'd opted for. Often it's fine, sometimes not, just a bit here and there and I lacked the or energy to diagnose the nuances, and developed a a general sense of frustration with it alas.

Inspecting the Clipboard (revisited) 🔍

So I looked for a simpler, more reliable and perhaps native solution to inspecting the clipboard contents closely, including it's MIME part breakdown.

As I'm on Linux I found the lowest level of reliable inspection was xclip easily installed on Debian/Ubuntu derived systems with sudo apt install xclip.

Subsequently I could see the contents in parts as follows:

xclip -selection clipboard -o -t TARGETS

After a copy operation, for example, I see:

$ xclip -selection clipboard -o -t TARGETS
TIMESTAMP
TARGETS
SAVE_TARGETS
MULTIPLE
STRING
UTF8_STRING
TEXT
text/plain
text/html
Enter fullscreen mode Exit fullscreen mode

And I can see the parts with:

xclip -selection clipboard -o -t text/plain

xclip -selection clipboard -o -t text/html

which works a dream. This can be piped through grep to find things, but the HTML is not formatted.

So I installed HTML tidy.

After which:

xclip -selection clipboard -o -t text/html | tidy -qi --wrap 0

Produces a nicely formatted view of the HTML MIME part.

And to get the size of the HTML on the clipboard:

xclip -selection clipboard -o -t text/html | wc -c | numfmt --to=iec

all of which proved very useful inspection and diagnostics when experimenting with what to copy and how.

copy Article's
30 articles in total
Favicon
Essential FFmpeg Recipes for Video Manipulation
Favicon
Unlocking Productivity: The Power of Keyboard Shortcuts
Favicon
Copy file between server and local machine ( from windows to linux server )
Favicon
Python's shutil module for Automated Testing
Favicon
The Pinnacle of Imitation: Master Copy Watches UAE Edition
Favicon
Two updates to the rucken copy-paste utility
Favicon
Docker Commands copy, remove images.
Favicon
How to load JSON data in PostgreSQL with the COPY command
Favicon
Looking forward experience developer
Favicon
OCP - OpenShift Container - Need to Copy Custom CA-Trust Certificates for Proxy Call from Company Domain to Azure
Favicon
Elevate Your Buttons with CopyShareify-js: Copy, Share, and More!
Favicon
Copying Files From Local To Remote Using PowerShell
Favicon
wayland & clipboard
Favicon
How to copy lots of data fast?
Favicon
Copy paste source files to destination with singular and plural replace text in file contents and file paths
Favicon
#010 Jira unformatted / formatted paste - How to paste plain text in Jira tickets | Jira messages - CTRL+SHIFT+V
Favicon
How to copy/paste files/directories into non-existent destination path
Favicon
Copy to Clipboard - Clipboard.js
Favicon
Copying Items to Clipboard Without Using Clipboard API
Favicon
Inspecting the Clipboard (on Linux)
Favicon
COPY progression in YugabyteDB
Favicon
HTML on the Clipboard: Oh, what shall we copy?
Favicon
Copy to Clipboard: The Options
Favicon
Copy to Clipboard: First Cut
Favicon
Bulk load into PostgreSQL / YugabyteDB - psycopg2
Favicon
Copy text to Clipboard using JavaScript
Favicon
How to Copy Array in Java
Favicon
[Dicas do VIM] Copiar, cortar e colar no VIM / NeoVim
Favicon
Creating copy button with JS
Favicon
Windows 10 copy multiple paste - shortcut/multiple paste option

Featured ones: