Skip to content

Instantly share code, notes, and snippets.

@ejfox
Created April 21, 2024 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejfox/e5c1a08c9c2950ab94431e130c49aa18 to your computer and use it in GitHub Desktop.
Save ejfox/e5c1a08c9c2950ab94431e130c49aa18 to your computer and use it in GitHub Desktop.
Folder action for screenshots folder to automatically upload to Cloudinary
#!/bin/bash
# API keys for Cloudinary
export CLOUDINARY_URL=cloudinary://keykeykey@cloudname
# Iterate over each passed argument
for file in "$@"
do
# Check if the file exists
if [ -f "$file" ]; then
# Upload to Cloudinary and capture output
upload_output=$(/opt/homebrew/bin/cld uploader upload "$file" use_filename=true unique_filename=false 2>&1)
upload_exit_status=$?
# Check if the upload was successful
if [ $upload_exit_status -eq 0 ]; then
# Attempt to extract the URL using the absolute path for jq
url=$(echo "$upload_output" | /opt/homebrew/bin/jq -r '.url' 2>/dev/null)
# Check if the URL is non-empty
if [ -n "$url" ]; then
echo "$url" | pbcopy
# Display success notification with the URL
osascript -e "display notification \"Uploaded $file to Cloudinary and URL copied to clipboard: $url\" with title \"Screenshot Upload\""
else
# Display notification for empty URL
osascript -e "display notification \"Failed to extract URL from output\" with title \"Debug\""
fi
else
# Display notification for upload failure
osascript -e "display notification \"Failed to upload $file to Cloudinary. Error: $upload_output\" with title \"Screenshot Upload\""
fi
else
# Display notification for file not found
osascript -e "display notification \"File does not exist: $file\" with title \"Debug\""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment