diff --git a/push-paperless.sh b/push-paperless.sh new file mode 100755 index 0000000..698dda1 --- /dev/null +++ b/push-paperless.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +# Required Raycast metadata parameters: +# @raycast.schemaVersion 1 +# @raycast.title Push Clipboard to Paperless +# @raycast.mode silent +# @raycast.packageName Automation +# @raycast.icon 📄 + +# 1. Configuration +API_URL="http://paperlss.duckdns.org:8008/api/documents/post_document/" +API_TOKEN="aee0db3c33917f4f68e07045c660b156eb2da0d4" +TIMESTAMP=$(date +%Y%m%d_%H%M%S) +DISPLAY_DATE=$(date "+%Y-%m-%d %H:%M:%S") + +# 2. Check if the clipboard contains an image first +HAS_IMAGE=$(osascript -e 'clipboard info' 2>/dev/null | grep -E "TIFF picture|PNG picture|JPEG picture") + +if [ -n "$HAS_IMAGE" ]; then + TMP_IMG=$(mktemp).png + osascript -e "write (the clipboard as «class PNGf») to (open for access POSIX file \"$TMP_IMG\" with write permission)" >/dev/null 2>&1 + + if [ ! -f "$TMP_IMG" ] || [ ! -s "$TMP_IMG" ]; then + echo "❌ Image extraction failed" + rm -f "$TMP_IMG" + exit 1 + fi + + STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ + -H "Authorization: Token $API_TOKEN" \ + -F "document=@${TMP_IMG};filename=clip_${TIMESTAMP}.png" \ + -F "title=Clipboard Image ($DISPLAY_DATE)" \ + "$API_URL") + + rm -f "$TMP_IMG" + + if [ "$STATUS_CODE" -eq 200 ] || [ "$STATUS_CODE" -eq 201 ]; then + echo "🖼️ Sent image to Paperless!" + exit 0 + else + echo "❌ Image upload failure (HTTP $STATUS_CODE)" + exit 1 + fi +fi + +# 3. Fallback: Process text by rendering directly to a full-length PNG image using Pillow +CLIP_TEXT=$(pbpaste) + +if [ -z "$CLIP_TEXT" ]; then + echo "❌ Clipboard is empty" + exit 1 +fi + +TMP_PNG=$(mktemp).png + +# Generate a high-resolution, single continuous image stream from text strings +python3 - <