QubesOS Screenshot Clipboard Solution

I often take screenshots and need to place them in various AppVMs. I automated this with a simple script. How it works:

  1. I press PrintScreen
  2. I select the area for which I want to take a screenshot
  3. A menu of currently running VMs appears (excluding e.g. templates or vaults)
  4. I select the target AppVM and click OK

The screenshot file is copied to the selected AppVM, and I can find the file itself in /home/user/QubesIncoming/name.png

How to do it?

  1. Check or install missing software: zenity and xfce4-screenshooter
sudo qubes-dom0-update xfce4-screenshooter
sudo qubes-dom0-update zenity
  1. Execute the commands to create the directory structure and place the previously mentioned script in $HOME/.local/bin/custom-screenshooter
# Run on dom0 as USER
mkdir -p $HOME/.local/bin
cat <<EOF > $HOME/.local/bin/custom-screenshooter
#!/bin/bash

screenshot_file="$HOME/Pictures/Screenshot_$(date +%F_%H-%M-%S).png"
xfce4-screenshooter -r -s "$screenshot_file"
if [[ -f "$screenshot_file" ]]
then
  vms=$(qvm-ls --running --raw-list --fields NAME |grep -vE '^(dom0$)|(debian|default|fedora|sys)-|vault$')
  target_vm=$( echo "$vms" | zenity --list --title="Copy to vm" --column="VM" --height=400 --width=300)
  if [[ -z "$target_vm" ]]
  then
    exit 1
  fi
  qvm-copy-to-vm "$target_vm" "$screenshot_file"
fi

EOF
chmod 700 $HOME/.local/bin/custom-screenshooter

As we know, you can’t copy to dom0 from the clipboard.So how do you copy this script? Copy it to a file in any AppVM and on dom0 copy the contents of the file to dom0:

qvm-run --pass-io YOUR_APPVM "cat /home/user/path/to/this/file.txt" > file.txt
  1. Set the keyboard shortcut. Qubes Application Menu → Settings Icon → Keyboard → Application Shortcuts → Add. In the ‘command’ field type /home/youruser/.local/bin/custom-screenshooter and select the key (e.g. PrintScreen).

Notes:

  • I use xfce4-screenshooter, although another one (e.g. built into kde Spectacle) is better. By better I mean that it allows more functionality, e.g. the ability to edit the screen, such as selecting something on it, simple cropping, etc. The tool is cool, but when I saw how many dependencies it requires - I gave up.
  • I think that such a solution (of course in a more advanced form) could be a nice feature for default qubes OS installations as, for example, a screenshooter configuration option, although it would probably be necessary to carefully consider how to implement it in a safe way.
4 Likes