Okay, so day 2 of Raycast blog work. I haven't blogged as much because it is still not a seamless experience - so I'm using Raycast to pull out those seams.
After much back and forth with Claude, I got a functioning script and this overview.
And just like that, we've uploaded this image to supabase.
Image generated in Midjourney with the prompt we out here --p to generate in my "personal Style"
The full workflow
generate image in Midjourney
copy the image to my clipboard
press option + shift + u to pull up the Raycast script.
Write the folder and file name to upload to and press enter
copy generated link - TADA
Current state
I now have two Raycast scripts to assist in publishing blog posts.
my blog post publishing script that I run via option + shift + Enter
my image bucket uploader script. I've assigned this to option + Shift + u. I can now upload any image directly to bucket storage and get the url back for embedding.
Next I need to think of other macros to build!! As soon as I'm doing a multi-part process more than once in a short period of time, it's Raycast script time.
I'm still in awe of the power and simplicity of Raycast.
Full Script
1#!/bin/bash23# Required parameters:4# @raycast.schemaVersion 15# @raycast.title Upload to Supabase6# @raycast.mode fullOutput7# @raycast.packageName Supabase89# Optional parameters:10# @raycast.icon π€11# @raycast.argument1 { "type": "text", "placeholder": "Folder path (e.g., images/blog)", "optional": false }12# @raycast.argument2 { "type": "text", "placeholder": "File name (without extension)", "optional": false }13# @raycast.needsConfirmation true14# @raycast.description Upload clipboard content to Supabase Storage1516echo"π Debug: Script starting"1718# Source environment variables19if[ -f "$(dirname"$0")/.env"];then20echo"π Debug: Found .env file"21source"$(dirname"$0")/.env"22else23echo"β Error: .env file not found at $(dirname"$0")/.env"24exit125fi2627# Check for required tools28if!command -v pngpaste &> /dev/null;then29echo"β οΈ pngpaste not found. Installing..."30 brew install pngpaste
31fi3233if!command -v magick &> /dev/null;then34echo"β οΈ ImageMagick not found. Installing..."35 brew install imagemagick
36fi3738# Get arguments39FOLDER_PATH=$140FILE_NAME=$24142# Create temporary directory43TEMP_DIR=$(mktemp -d)44echo"π Debug: Created temp directory at $TEMP_DIR"4546# Get clipboard info for format detection47CLIPBOARD_INFO=$(osascript -e 'clipboard info')48echo"π Debug: Clipboard info: $CLIPBOARD_INFO"4950# Determine desired output format from clipboard info51# Prioritize actual image formats over text representations52if[[$CLIPBOARD_INFO== *"Β«class JPEGΒ»"* ||$CLIPBOARD_INFO== *"JPEG picture"* ]];then53FORMAT="jpg"54MIME_TYPE="image/jpeg"55echo"π Debug: JPEG format detected in clipboard"56elif[[$CLIPBOARD_INFO== *"Β«class GIFfΒ»"* ||$CLIPBOARD_INFO== *"GIF picture"* ]];then57FORMAT="gif"58MIME_TYPE="image/gif"59echo"π Debug: GIF format detected in clipboard"60elif[[$CLIPBOARD_INFO== *"TIFF"* ]];then61FORMAT="tiff"62MIME_TYPE="image/tiff"63echo"π Debug: TIFF format detected in clipboard"64else65FORMAT="png"66MIME_TYPE="image/png"67echo"π Debug: Defaulting to PNG format"68fi6970# Set up temp file paths71TEMP_PNG="$TEMP_DIR/initial.png"72TEMP_FILE="$TEMP_DIR/image.$FORMAT"7374# First capture with pngpaste75if pngpaste "$TEMP_PNG";then76echo"β Successfully captured clipboard to PNG"7778# Verify the captured PNG79if! magick identify "$TEMP_PNG"&>/dev/null;then80echo"β Invalid image captured"81rm -rf "$TEMP_DIR"82exit183fi8485if["$FORMAT"="png"];then86echo"π Using PNG format directly"87mv"$TEMP_PNG""$TEMP_FILE"88else89echo"π Converting from PNG to $FORMAT"90if magick "$TEMP_PNG" -quality 100"$TEMP_FILE";then91# Verify conversion worked92ACTUAL_FORMAT=$(magick identify -format "%m""$TEMP_FILE")93echo"π Debug: Actual output format: $ACTUAL_FORMAT"9495if[[$ACTUAL_FORMAT!= *"$FORMAT"* ]];then96echo"β οΈ Format conversion failed, falling back to PNG"97FORMAT="png"98MIME_TYPE="image/png"99mv"$TEMP_PNG""$TEMP_FILE"100else101echo"β Successfully converted to $FORMAT"102fi103else104echo"β οΈ Conversion failed, falling back to PNG"105FORMAT="png"106MIME_TYPE="image/png"107mv"$TEMP_PNG""$TEMP_FILE"108fi109fi110else111echo"β Failed to capture image from clipboard"112rm -rf "$TEMP_DIR"113exit1114fi115116CLIPBOARD_SIZE=$(wc -c <"$TEMP_FILE"|tr -d ' ')117echo"π€ Debug: File size: $CLIPBOARD_SIZE bytes"118119# Remove leading/trailing slashes from folder path120FOLDER_PATH=$(echo $FOLDER_PATH |sed's:^/::'|sed's:/$::')121FULL_PATH="${FOLDER_PATH}/${FILE_NAME}.${FORMAT}"122123echo"π Debug: Target path will be: $FULL_PATH"124125# Check if file has content126if["$CLIPBOARD_SIZE" -eq 0];then127echo"β Error: No content was saved!"128rm -rf "$TEMP_DIR"129exit1130fi131132echo"π Debug: Starting upload to Supabase"133echo"π€ Uploading to: $FULL_PATH"134echo"π Using bucket: $BUCKET_NAME"135136# Upload to Supabase137RESPONSE=$(curl -s -X POST "$SUPABASE_URL/storage/v1/object/$BUCKET_NAME/$FULL_PATH"\138 -H "Authorization: Bearer $SUPABASE_KEY"\139 -H "Content-Type: $MIME_TYPE"\140 --data-binary "@$TEMP_FILE")141142# Clean up temp directory143rm -rf "$TEMP_DIR"144echo"π§Ή Debug: Cleaned up temp directory"145146if[[$RESPONSE== *"Key"* ]];then147echo"β Upload successful!"148echo"π URL: $SUPABASE_URL/storage/v1/object/public/$BUCKET_NAME/$FULL_PATH"149echo"$RESPONSE"150else151echo"β Upload failed!"152echo"Error: $RESPONSE"153exit1154fi