Hi there! I am trying to create a workflow in Alfred that search a keyword and returns a relevant photo from unsplash using the unsplash api.
#!/usr/bin/env bash
# Set Unsplash API key
export UNSPLASH_ACCESS_KEY="enter your unsplash key"
# Get query from Alfred
query="$1"
# URL encode query
query="$(echo "$query" | python -c 'import urllib.parse; print(urllib.parse.quote(input()))')"
# Search for images on Unsplash using the Unsplash API
response=$(curl --silent "https://api.unsplash.com/search/photos?query=$query&client_id=$UNSPLASH_ACCESS_KEY")
# Parse the JSON response to get the URLs of the first 10 images
urls=$(echo "$response" | jq -r '.results[0:10] | .[].urls.regular')
# Output the URLs as JSON for Alfred
echo "$urls" | jq -R -s 'split("\n") | map(select(length > 0)) | map({title: ., arg: .})'
The workflow doesn't run as expected. Does anyone know what may be wrong?