Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
apps:xfce4-screenshooter:custom-actions [2025/01/15 22:52] – add imgur link dialog kevinbowenapps:xfce4-screenshooter:custom-actions [2026/11/22 16:34] (current) – Refresh custom actions page epetriglia
Line 2: Line 2:
 {{ :apps:xfce4-screenshooter.png?nolink|}} {{ :apps:xfce4-screenshooter.png?nolink|}}
 ====== xfce4-screenshooter - Custom Actions ====== ====== 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 [[:apps:xfce4-screenshooter:usage#after_capturing|After capturing]]): select {gui>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 [[:apps:xfce4-screenshooter:panel-plugin|panel plugin]].
  
   * **[[#Adding custom actions|Adding custom actions]]**   * **[[#Adding custom actions|Adding custom actions]]**
 +  * **[[#How commands are executed|How commands are executed]]**
   * **[[#Examples|Examples]]**   * **[[#Examples|Examples]]**
     * **[[#Extract text with OCR|Extract text with OCR]]**     * **[[#Extract text with OCR|Extract text with OCR]]**
     * **[[#Read QR Code|Read QR Code]]**     * **[[#Read QR Code|Read QR Code]]**
-    * **[[#Host on Imgur™|Host on Imgur™]]**+    * **[[#Hosting on Imgur™|Hosting on Imgur™]]** 
 + 
 +----
  
 ===== Adding custom actions ===== ===== Adding custom actions =====
 +
 +Custom actions are added, removed and edited in the {gui>Preferences} dialog, which can be opened with the {gui>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 {gui>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 ''%f'' as a placeholder for the location of the captured screenshot.
  
 <figure "xfce4-screenshooter Preferences Window"> <figure "xfce4-screenshooter Preferences Window">
Line 15: Line 33:
 </figure> </figure>
  
-Custom actions can be added, removed and editing in the Preferences dialog.+[[|Back to Top]]
  
-  * 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: +===== How commands are executed ===== 
-  * 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.+  * ''%f'' is replaced with the full path of the screenshot, already quoted, so file names containing spaces are handled correctly. Do not add quotes around ''%f'' yourself. 
 +  * Environment variables such as ''$HOME'' are expanded, so a command like ''$HOME/bin/upload.sh %f'' works. 
 +  * 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. 
 + 
 +[[|Back to Top]]
  
 ---- ----
Line 29: Line 51:
 ===== Examples ===== ===== Examples =====
  
-The following examples assume the necessary dependencies are already installed.+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 ==== ==== Extract text with OCR ====
  
-''gimagereader-gtk %f''+Set as command: ''gimagereader-gtk %f'' 
 + 
 +[[|Back to Top]]
  
 ---- ----
Line 39: Line 63:
 ==== Read QR Code ==== ==== Read QR Code ====
  
-Save the following script somewhere and set as command: ''<somewhere>/read-qr.sh %f''+Save the following script somewhere, make it executable (''chmod +x read-qr.sh'') and set as command: ''<somewhere>/read-qr.sh %f''
  
-<code>+<code bash read-qr.sh>
 #!/bin/bash #!/bin/bash
  
Line 60: Line 84:
 ---- ----
  
-==== Host on Imgur™ ====+==== Hosting on Imgur™ ====
  
-Save the following script somewhere and set as command: ''<somewhere>/imgur-upload.sh %f <CLIENT ID>'' +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.
-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.+
  
-<code> +<note important>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 [[https://imgur.com/tos|Terms of service]], if you do not agree with the terms please refrain from using this service.</note> 
-#!/bin/sh+ 
 +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''. 
 + 
 +<note warning>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.</note> 
 + 
 +<code bash imgur.sh> 
 +#!/usr/bin/env bash
  
 URL='https://api.imgur.com/3/image' URL='https://api.imgur.com/3/image'
Line 77: Line 106:
 fi 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}' +if ! command -v jq >&2; then 
-#RESPONSE='{"data":{"error":{"code":1003,"message":"File type invalid (1)","type":"ImgurException","exception":[]},"request":"\/3\/image","method":"POST"},"success":false,"status":400}' +    zenity --error --text="jq: command not found!" 
-RESPONSE=$(curl --silent --location "$URL" --header "Authorization: Client-ID $CLIENT_ID" --form "image=@$SCREENSHOT_PATH")+    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) STATUS=$(echo "$RESPONSE" | jq -r .status)
  
-if [ -z "$STATUS" ] || [ $STATUS -ne 200 ]; then+if [ -z "$STATUS" ] || [ "$STATUS" -ne 200 ]; then
     ERROR=$(echo "$RESPONSE" | jq -r .data.error.message)     ERROR=$(echo "$RESPONSE" | jq -r .data.error.message)
     zenity --error --text="Failed to upload screenshot:\n$ERROR"     zenity --error --text="Failed to upload screenshot:\n$ERROR"
Line 94: Line 129:
  
 # Add link to clipboard # Add link to clipboard
-echo "$LINK" | xclip -selection c+echo "$LINK" | xclip -selection clipboard
  
 # Add links to log # Add links to log
Line 111: Line 146:
 </code> </code>
  
-The dialog below will give you the links to delete the image off of the Imgur website. The link will only be shown once. Make sure to save it if you think you might be deleting this image: +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:
  
 <figure "Imgur Deletion Dialog Window"> <figure "Imgur Deletion Dialog Window">
 {{:apps:xfce4-screenshooter:xfce4-screenshooter-custom-action-imgur.png|Imgur Deletion Dialog Window}} {{:apps:xfce4-screenshooter:xfce4-screenshooter-custom-action-imgur.png|Imgur Deletion Dialog Window}}
 </figure> </figure>
- 
  
 [[|Back to Top]] [[|Back to Top]]
  
 ---- ----
-[[:apps:screenshooter:start:|Return to xfce4-screenshooter Main Documentation Page]]+[[:apps:xfce4-screenshooter:start|Return to xfce4-screenshooter Main Documentation Page]]