Skip to content

Instantly share code, notes, and snippets.

@ianfoo
Created May 24, 2023 01:17
Show Gist options
  • Save ianfoo/506f0b8de51533169ad1f7039d85adc6 to your computer and use it in GitHub Desktop.
Save ianfoo/506f0b8de51533169ad1f7039d85adc6 to your computer and use it in GitHub Desktop.
xbar action to show current playing selection on JEMP radio, with help from https://github.com/ianfoo/ph and jq
#!/usr/bin/env bash
PATH=$HOME/bin:/opt/homebrew/bin:$PATH
output_vars () {
ph --format json | jq -r '"TITLE=\"\(.title)\"\nARTIST=\"\(.artist)\"\nDATE=\"\(.performance_time)\""'
}
eval $(output_vars)
OUTPUT="$TITLE"
if [[ -n $ARTIST ]]; then
OUTPUT="$OUTPUT • $ARTIST"
fi
if [[ $DATE != "0001-01-01T00:00:00Z" ]]; then
# BSD `date` does not understand "Z" as a time zone, so replace
# it with an explicit timezone offset.
reformatted_date=$(echo "$DATE" | sed 's/Z$/+0000/')
# Note that this invocation of `date` is for BSD date,
# not GNU date, which will use different command line flags.
date_only=$(date -jf "%Y-%m-%dT%H:%M:%S%z" "$reformatted_date" "+%Y-%m-%d")
OUTPUT="$OUTPUT • $date_only"
fi
echo "$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment