#!/bin/bash

generate() {
    message=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
    volume=$(awk '{print $2 * 100}' <<< "$message")

    if [[ $(awk '{print $3}' <<< "$message") == "[MUTED]" ]]; then
        muted=1
    else
        muted=0
    fi

    echo '{"volume":"'$volume'","muted":"'$muted'"}'
}

generate

pactl subscribe | while read -r event; do
    if [[ "$event" == *"Event 'change'"* ]]; then
        
        generate

    fi
done
