Last active
January 9, 2024 19:05
-
-
Save ejfox/1ba2ea7cb45099790ef417fd2ef335fa to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# API keys for Cloudinary | |
export CLOUDINARY_URL=cloudinary://APIKEY@NAME | |
# 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=$(/usr/local/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" | /usr/local/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