Writing
Taking and uploading screenshots on Linux
A Bash workflow that captures a Flameshot screenshot, uploads it to s-ul.eu and copies the resulting URL.
I wanted one shortcut that could capture a region, upload the image and leave a shareable URL in my clipboard. This Bash script connects Flameshot to s-ul.eu, with separate clipboard handling for X11 and Wayland.
The implementation builds on s-ul-curl-uploader and this Flameshot issue.
What you need
- flameshot
- curl
- libnotify
- xclip
- wl-clipboard
- jq
Install the dependencies on Arch
sudo pacman -S flameshot curl libnotify xclip wl-clipboard jq
Install the uploader
Download it
curl -o /home/$USER/.local/bin/sul-uploader https://gist.github.com/maotovisk/1a6a50c90982535bbaa69f6d8203ac74/raw/356f80ecc41587d09c0c68c84099c1c81f326002/sul-uploader
Read the script
#!/bin/bash
app_name="S-UL"
# Dependencies: curl, notify-send, xclip, wl-clipboard, jq
function _notify()
{
notify-send --expire-time 1000 \
--app-name "$app_name" \
--icon 'flameshot' \
"$1" "$2"
}
store_directory=/home/$USER/s-ul
if [[ ! -e $store_directory ]]; then
mkdir $store_directory
fi
current_date=`date +"%Y-%m-%d %H-%M-%S"`
filename="Screenshot_$current_date.png"
complete_path="${store_directory}/${filename}"
flameshot gui -r >> "$complete_path"
if [[ $(file --mime-type -b "$complete_path") != "image/png" ]]; then
rm "$complete_path"
_notify "$app_name" "Screenshot aborted" && exit 1
fi
key="YOUR_API_KEY_HERE"
method=POST
postURL=https://s-ul.eu/api/v1/upload
wizard=true
file="$complete_path"
actualsize=$(wc -c <"$file")
maxsize=209714177
if [ $actualsize -ge $maxsize ]; then
_notify "\nSorry, your file is too large to be uploaded. Please try a smaller file.\n";
fi
_notify "$app_name" 'Uploading screenshot...'
read url < <(echo $(curl -s -X ""$method"" """$postURL""?key=""$key""&wizard=""$wizard"""" -F"file=@\"""$file""\"" | jq -r '.url'))
if [ -z "$url" ]; then
_notify "$app_name" "Error: Error while uploading"
else
if [ $XDG_SESSION_TYPE = "x11" ]; then
echo -n "$url" | xclip -selection clipboard
else
wl-copy "$url"
fi
_notify "$app_name" 'Success! The link was sent to your clipboard'
fi
Finish the setup
- Make the file executable with
chmod +x .local/bin/sul-uploader; - Put your s-ul API key in the
keyvariable. It is available in your s-ul.eu account configuration; - Add a desktop-environment shortcut that runs the script;
- Use the full path
/home/$USER/.local/bin/sul-uploader. Most desktop environments do not include.local/bininPATHwhen they launch a shortcut.
- Use the full path