Wayland screenshot

In a previous post I described how I upload screenshots to a bepasty-server. Since then I switched from xorg/i3 to wayland/sway and the screenshot script changed quite a bit.

My current takescreenshot.sh looks like this:

#!/bin/bash

grim -g "$(slurp)" /tmp/screen.png
if [ "$?" -eq "0" ]; then
    cat /tmp/screen.png | wl-copy
    result=$(python ~/bin/bepasty-upload-image.py -p PASSWORD -u https://some-paste-bin-url.example -f /tmp/screen.png)
    if [ "$?" -ne "0" ]; then
        echo $result; exit 1
    fi
    xdg-open $(echo $result | head -n 1)
fi

The tools used are slurp to select the screen or area on the screen and grim to save the selection as an image. The image is saved in /tmp and if the return code from grim is 0 the copy and upload is started. This return code detection allows me to press Escape to not take a screenshot without triggering the upload. My current most frequent workflow is to paste the image into slack, so the image is put into the clipboard via wl-copy. Then the image is uploaded to the paste-bin and a browser window is opened showing the image in the paste-bin.