xfce4-screenshooter - Custom Actions

Custom actions let you process a screenshot with any program or script right after it is captured: for example to edit it, extract its text, read a QR code or upload it to an online service. Once configured, they appear in the window shown after capturing (see After capturing): select Custom Action, choose the action from the drop-down list and confirm. The screenshot is saved to the system's temporary directory and passed to the command.

Custom actions are available both in the application and in the panel plugin.


Adding custom actions

Custom actions are added, removed and edited in the Preferences dialog, which can be opened with the Preferences button of the main window or of the panel plugin's properties dialog.

Each custom action is composed of:

xfce4-screenshooter Preferences Window
xfce4-screenshooter Preferences Window

Back to Top


How commands are executed

Back to Top


Examples

The following examples assume the necessary dependencies are already installed. The clipboard examples use xclip, which works on X11, on Wayland replace xclip -selection clipboard with wl-copy.

Extract text with OCR

Set as command: gimagereader-gtk %f

Back to Top


Read QR Code

Save the following script somewhere, make it executable (chmod +x read-qr.sh) and set as command: <somewhere>/read-qr.sh %f

read-qr.sh
#!/bin/bash
 
RES=$(zbarimg --raw "$1" 2> /dev/null)
if [ $? -ne 0 ]; then
    notify-send -e "No QR Code detected"
    exit 0
fi
 
ANSWER=$(notify-send -e -A 1="Copy to clipboard" -t 5000 "QR Code detected" "$RES")
if [ "$ANSWER" == "1" ]; then
    echo "$RES" | xclip -selection clipboard
fi

Back to Top


Hosting on Imgur™

This custom action allows you to host your screenshot on this free online hosting service, so that you can share it easily with other people. Imgur automatically generates a tiny, medium, and full-size image of your screenshot, which can be used to create thumbnails pointing to the full size screenshot.

Hosting images in a public-facing service must be done with caution, as it is not possible to guarantee the removal of an image after publishing it. Before using this action, please review Imgur's Terms of service, if you do not agree with the terms please refrain from using this service.

You need to register at Imgur and obtain your client ID. Then save the following script somewhere, make it executable (chmod +x imgur.sh) and set as command: <somewhere>/imgur.sh %f <CLIENT ID>. The script requires curl, jq, zenity and xclip.

Do not name the script imgur-upload.sh: custom actions whose command contains that name are removed automatically, because it was the name of the old built-in Imgur action.
imgur.sh
#!/usr/bin/env bash
 
URL='https://api.imgur.com/3/image'
SCREENSHOT_PATH=$1
CLIENT_ID=$2
 
if [ -z "$SCREENSHOT_PATH" ] || [ -z "$CLIENT_ID" ]; then
    zenity --error --text="Arguments are missing"
    exit 1
fi
 
if ! command -v jq >&2; then
    zenity --error --text="jq: command not found!"
    exit 1
fi
 
RESPONSE=$(curl --silent --location "$URL" \
    --header "Authorization: Client-ID $CLIENT_ID" \
    --form "image=@$SCREENSHOT_PATH" | \
    tee >(zenity --progress --pulsate --no-cancel --auto-close --text="Uploading screenshot..."))
STATUS=$(echo "$RESPONSE" | jq -r .status)
 
if [ -z "$STATUS" ] || [ "$STATUS" -ne 200 ]; then
    ERROR=$(echo "$RESPONSE" | jq -r .data.error.message)
    zenity --error --text="Failed to upload screenshot:\n$ERROR"
    exit 1
fi
 
LINK="https://imgur.com/$(echo "$RESPONSE" | jq -r .data.id).png"
DELETE="https://imgur.com/delete/$(echo "$RESPONSE" | jq -r .data.deletehash)"
LOG_DIRECTORY="${XDG_DATA_HOME:-$HOME/.local/share}/xfce4"
LOG="$LOG_DIRECTORY/xfce4-screenshooter-imgur.log"
 
# Add link to clipboard
echo "$LINK" | xclip -selection clipboard
 
# Add links to log
mkdir -p "$LOG_DIRECTORY"
echo "---
$(date '+%x %X')
Link: $LINK
Delete: $DELETE" >> "$LOG"
 
# Show dialog with links
zenity --info --title="Screenshot uploaded" --text="Link: <a href='$LINK'>$LINK</a>
Delete: <a href='$DELETE'>$DELETE</a>
 
Link copied to clipboard. Links stored in:
$LOG"

After the upload, the dialog below shows the link to the image and the link to delete it from the Imgur website. Both links are copied to a log file (~/.local/share/xfce4/xfce4-screenshooter-imgur.log), so you can still delete the image later:

Imgur Deletion Dialog Window
Imgur Deletion Dialog Window

Back to Top


Return to xfce4-screenshooter Main Documentation Page