This is an old revision of the document!
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.
- Add: click on the plus (+) button. A new blank custom action is added at the bottom of the list.
- Remove: select a custom action and click on the minus (-) button.
- Edit: select a custom action and change its name and command. Changes are saved when the Preferences dialog is closed.
Each custom action is composed of:
- Name: a friendly name that will be shown in the drop-down list of the Actions dialog.
- Command: the command to be executed. It can be an inline command or a call to a script. Use
%fas a placeholder for the location of the captured screenshot.
| xfce4-screenshooter Preferences Window |
|---|
|
How commands are executed
%fis replaced with the full path of the screenshot, already quoted, so file names containing spaces are handled correctly. Do not add quotes around%fyourself.- Environment variables such as
$HOMEare expanded, so a command like$HOME/bin/upload.sh %fworks. - The command is executed directly, this means pipes (
|), redirections (>) and other shell syntax are not supported. If you need them, put the commands in a script and call the script. - Programs without a full path are searched in
$PATH. - Only the command line is stored, not the script it calls. The script is run again on every use, so changes to it take effect immediately, without editing the custom action.
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
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
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.
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.
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 |
|---|
|

