Created
March 31, 2026 22:09
-
-
Save markhc/e926a71dde8b5defe768f7addabbe32f to your computer and use it in GitHub Desktop.
Flameshot Custom Upload Host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # flameshot-upload.sh | |
| # Takes a screenshot with Flameshot, uploads it to isrv.nl, and copies the URL to clipboard. | |
| set -euo pipefail | |
| UPLOAD_URL="https://isrv.nl" | |
| TMPDIR_BASE="/tmp/flameshot-upload" | |
| mkdir -p "$TMPDIR_BASE" | |
| TMPFILE="$TMPDIR_BASE/screenshot_$(date +%s%N).png" | |
| # ── 1. Check dependencies ───────────────────────────────────────────────────── | |
| for cmd in wl-paste wl-copy jq curl; do | |
| if ! command -v "$cmd" &>/dev/null; then | |
| notify-send -u critical "Flameshot Upload" "'$cmd' is not installed." | |
| exit 1 | |
| fi | |
| done | |
| # ── 2. Launch Flameshot and wait for it to finish ──────────────────────────── | |
| QT_QPA_PLATFORM=xcb flameshot gui -c | |
| # flameshot exits after the user captures or cancels | |
| # ── 3. Give the clipboard a moment to settle ───────────────────────────────── | |
| sleep 0.3 | |
| # ── 4. Pull image data from clipboard ──────────────────────────────────────── | |
| # wl-paste --list-types shows what MIME types are currently in the clipboard. | |
| CLIPBOARD_TYPES=$(wl-paste --list-types 2>/dev/null || true) | |
| if echo "$CLIPBOARD_TYPES" | grep -q "image/png"; then | |
| # Clipboard contains raw PNG image bytes — save them directly | |
| wl-paste --type image/png > "$TMPFILE" | |
| elif echo "$CLIPBOARD_TYPES" | grep -q "text/uri-list\|text/plain"; then | |
| # Clipboard contains a file path or URI | |
| CLIP_TEXT=$(wl-paste --type text/plain 2>/dev/null || true) | |
| # Strip file:// prefix if present | |
| FILEPATH="${CLIP_TEXT#file://}" | |
| FILEPATH=$(echo "$FILEPATH" | tr -d '[:space:]') | |
| if [[ -f "$FILEPATH" ]]; then | |
| cp "$FILEPATH" "$TMPFILE" | |
| else | |
| notify-send -u critical "Flameshot Upload" "Could not find screenshot file: $FILEPATH" | |
| exit 1 | |
| fi | |
| else | |
| notify-send -u critical "Flameshot Upload" "No image found in clipboard. Did you cancel the screenshot?" | |
| exit 0 | |
| fi | |
| # ── 5. Sanity-check: make sure we actually got a valid PNG ─────────────────── | |
| if [[ ! -s "$TMPFILE" ]]; then | |
| notify-send -u critical "Flameshot Upload" "Clipboard image was empty. Upload aborted." | |
| rm -f "$TMPFILE" | |
| exit 1 | |
| fi | |
| # ── 6. Upload to isrv.nl ───────────────────────────────────────────────────── | |
| notify-send "Flameshot Upload" "Uploading screenshot…" | |
| RESPONSE=$(curl --silent --fail \ | |
| -F "file=@${TMPFILE}" \ | |
| "$UPLOAD_URL" 2>&1) || { | |
| notify-send -u critical "Flameshot Upload" "Upload failed. Check your connection." | |
| rm -f "$TMPFILE" | |
| exit 1 | |
| } | |
| # ── 7. Parse the returned JSON for the URL ─────────────────────────────────── | |
| STATUS=$(echo "$RESPONSE" | jq -r '.status // "error"') | |
| if [[ "$STATUS" != "success" ]]; then | |
| notify-send -u critical "Flameshot Upload" "Server error: $RESPONSE" | |
| rm -f "$TMPFILE" | |
| exit 1 | |
| fi | |
| FILE_URL=$(echo "$RESPONSE" | jq -r '.filename') | |
| # ── 8. Copy the URL to clipboard ───────────────────────────────────────────── | |
| echo -n "$FILE_URL" | wl-copy | |
| # ── 9. Done — notify the user ──────────────────────────────────────────────── | |
| notify-send "Flameshot Upload" "✅ Copied to clipboard:\n$FILE_URL" | |
| # Clean up | |
| rm -f "$TMPFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment