Uploaders

Spectacle on KDE

KDE's screenshot tool, run from a script that uploads and copies the link.

1. Make an uploader on your server

  1. Sign in to your server and open Settings > Uploaders, then Add uploader.
  2. Pick Spectacle, give it a name you'll recognize, and check the folder, visibility and link style. The defaults are fine.
  3. The next page has these same steps with your server and token already filled in. The token is shown once, so copy it or download the files now.

The snippets below use https://drive.example.com and stu_YOUR_UPLOADER_TOKEN. Swap in your own if you set things up by hand.

2. Install

  1. Install curl, jq and a clipboard tool if you don't have them:
    bash
    sudo apt install curl jq wl-clipboard xclip
  2. Download stavo-spectacle.sh from the uploader's page (or save the script below), put it in ~/.local/bin and make it runnable:
    bash
    mkdir -p ~/.local/bin
    mv ~/Downloads/stavo-spectacle.sh ~/.local/bin/
    chmod +x ~/.local/bin/stavo-spectacle.sh
  3. System Settings > Keyboard > Shortcuts > Add New > Command or Script, enter the line below and pick a key.
    bash
    ~/.local/bin/stavo-spectacle.sh
  4. Press the key and select an area. The link is on your clipboard. For the whole screen change -r to -f in the script, or -a for the active window.

The script

bash
#!/usr/bin/env bash
# Spectacle: select an area, it uploads and copies the link.
# Pass file paths to upload those instead.
# Needs: spectacle, curl, jq, and wl-copy (Wayland) or xclip (X11).
set -euo pipefail

SERVER="https://drive.example.com"
TOKEN="stu_YOUR_UPLOADER_TOKEN"

upload() {
  local resp url
  resp="$(curl -sS -H "Authorization: Bearer $TOKEN" -F "file=@$1" "$SERVER/api/v1/upload")" || { notify-send "Upload failed" "Couldn't reach $SERVER"; exit 1; }
  url="$(printf '%s' "$resp" | jq -r '.url // empty')"
  if [ -z "$url" ]; then
    notify-send "Upload failed" "$(printf '%s' "$resp" | jq -r '.error // "No answer from the server"')"
    exit 1
  fi
  if [ -n "${WAYLAND_DISPLAY:-}" ] && command -v wl-copy >/dev/null; then printf '%s' "$url" | wl-copy
  else printf '%s' "$url" | xclip -selection clipboard; fi
  notify-send "Link copied" "$url"
}

if [ "$#" -gt 0 ]; then
  for f in "$@"; do upload "$f"; done
  exit 0
fi

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
shot="$tmp/screenshot-$(date +%Y-%m-%d-%H%M%S).png"
# -b background, -n no notification, -r region, -o output file. Use -f for the screen or -a for the active window.
spectacle -b -n -r -o "$shot" || true
[ -s "$shot" ] || exit 0
upload "$shot"