~~NOTOC~~
{{ :apps:xfce4-screenshooter.png?nolink|}}
====== xfce4-screenshooter - Custom Actions ======
* **[[#Adding custom actions|Adding custom actions]]**
* **[[#Examples|Examples]]**
* **[[#Extract text with OCR|Extract text with OCR]]**
* **[[#Read QR Code|Read QR Code]]**
* **[[#Host on Imgur™|Host on Imgur™]]**
===== Adding custom actions =====
Custom actions can be added, removed and editing in the Preferences dialog.
* Add: click on the plus(+) button and a new blank custom action is added at the bottom of the list.
* Remove: click on the minus(-) button and the selected custom action will be removed.
* Edit: add a new custom action or select an existing one, changes made to the name and command entries are saved as soon as the preferences dialog is closed.
Custom actions are composed of:
* Name: a friendly name that will be shown in the Actions dialog.
* Command: command to be executed, it can be an inline command or a call to script. The screenshot file can be referenced by passing ''%f'' as parameter.
----
===== Examples =====
The following examples assume the necessary dependencies are already installed.
==== Extract text with OCR ====
''gimagereader-gtk %f''
----
==== Read QR Code ====
Save the following script somewhere and set as command: ''/read-qr.sh %f''
#!/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]]
----
==== Host on Imgur™ ====
Save the following script somewhere and set as command: ''/imgur-upload.sh %f ''
For the time being, screenshooter provides its own client id as ''%imgur_client_id'', in future releases that will be removed, you will need to register at Imgur and obtain your client id.
#!/bin/sh
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
#RESPONSE='{"data":{"id":"q9a8Oh4","title":null,"description":null,"datetime":1690124891,"type":"image\/png","animated":false,"width":217,"height":186,"size":593,"views":0,"bandwidth":0,"vote":null,"favorite":false,"nsfw":null,"section":null,"account_url":null,"account_id":0,"is_ad":false,"in_most_viral":false,"has_sound":false,"tags":[],"ad_type":0,"ad_url":"","edited":"0","in_gallery":false,"deletehash":"b0AjSDJjSU4iyhE","name":"","link":"https:\/\/i.imgur.com\/q9a8Oh4.png"},"success":true,"status":200}'
#RESPONSE='{"data":{"error":{"code":1003,"message":"File type invalid (1)","type":"ImgurException","exception":[]},"request":"\/3\/image","method":"POST"},"success":false,"status":400}'
RESPONSE=$(curl --silent --location "$URL" --header "Authorization: Client-ID $CLIENT_ID" --form "image=@$SCREENSHOT_PATH")
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 c
# 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: $LINK
Delete: $DELETE
Link copied to clipboard. Links stored in:
$LOG"
[[|Back to Top]]
----
[[:apps:screenshooter:start:|Return to xfce4-screenshooter Main Documentation Page]]