I don’t think I’ll use this a ton day-to-day because I haven’t put anything in flickr for a while, and generally use SmugMug these days for embedding stuff in a blog, but I’ve been learning how Raycast script actions work and this was an exercise in how to pass arguments in an action instead of going out to osascript dialogs.
- Visit a flickr image in Safari or Chrome
- Invoke the action from Raycast and:
- select a snippet format
- type in some alt text
- Get a snippet in Markdown, org, or HTML with your alt text, suitable for pasting into a blog post
Why you want to do this:
- If you’re all in on Flickr, then your blog becomes more easily portable if you ever move it, because the image tags have a stable URL
- Flickr cares more about the quality of the embeds than a lot of blogging providers.
- You’re using lmno or some other service that doesn’t manage image uploads at all, and you have to have a third party host.
Pick your poison: If you’re a forward-thinking SSG kinda person who has made it easy to ensure image tag hygiene in the event of a domain or platform change, this might not be appealing. If you’ve been doing this for 25 or 30 years and occasionally stray into the less portable corners of the web, but are willing to hitch your wagon to flickr, this is an option that compares favorably to “all your images were ingested, compressed into a mealy, blurry mess, and given an indecipherable path to some S3 bucket.” If you’re constantly playing around and moving posts back and forth between providers and frameworks, this could also be a helpful strategy.
#!/usr/bin/env bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Flickr snippet from active tab
# @raycast.mode silent
# @raycast.icon 🌄
# @raycast.description Grab the URL of your frontmost browser tab (Flickr only) and copy a Markdown/Org/HTML <img> snippet
# @raycast.argument1 { "type": "dropdown", "placeholder": "Format", "optional": false, "data": [ { "title": "Markdown", "value": "md" }, { "title": "Org‑mode", "value": "org" }, { "title": "HTML", "value": "html" } ] }
# @raycast.argument2 { "type": "text", "placeholder": "Alt text (optional)", "optional": true }
set -euo pipefail
FORMAT=$1
ALT_TEXT=${2:-""}
# 1) Get frontmost browser’s URL
APP=$(osascript -e 'tell application "System Events" to name of first application process whose frontmost is true')
case "$APP" in
Safari)
URL=$(osascript -e 'tell application "Safari" to return URL of front document') # :contentReference[oaicite:0]{index=0}
;;
"Google Chrome" | "Brave Browser" | "Microsoft Edge")
URL=$(osascript -e 'tell application "Google Chrome" to return URL of active tab of first window') # :contentReference[oaicite:1]{index=1}
;;
*)
echo "⚠️ Unsupported app: $APP"
exit 1
;;
esac
# 2) Validate it’s a Flickr photo page
if [[ ! $URL =~ https?://(www\.)?flickr\.com/photos/ ]]; then
echo "⚠️ Not a Flickr photo URL: $URL"
exit 1
fi
# 3) oEmbed → JSON
ENC=$(python3 -c 'import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=""))' "$URL")
OEMBED=$(curl -s "https://www.flickr.com/services/oembed?format=json&url=$ENC")
# 4) Extract direct image URL
IMG_URL=$(echo "$OEMBED" | /usr/bin/jq -r .url)
if [[ -z $IMG_URL || $IMG_URL == "null" ]]; then
echo "⚠️ Failed to extract image URL."
exit 1
fi
# 5) Build snippet
case $FORMAT in
md)
[[ -n $ALT_TEXT ]] && SNIP="" || SNIP=""
;;
org)
[[ -n $ALT_TEXT ]] && SNIP="[[${IMG_URL}][${ALT_TEXT//\]/\\]}]]" || SNIP="[[${IMG_URL}]]"
;;
html)
[[ -n $ALT_TEXT ]] && SNIP="<img src=\"$IMG_URL\" alt=\"${ALT_TEXT//\"/\\\"}\">" || SNIP="<img src=\"$IMG_URL\">"
;;
esac
# 6) Copy & notify
printf '%s' "$SNIP" | pbcopy
terminal-notifier -title "Flickr snippet" -message "Copied $FORMAT snippet" -sound default