Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- action="$1"
- node="$2"
- value="$3"
- # Validate there's an argument
- if [ -z "$value" ]; then
- echo "Usage: $0 <set-volume|set-mute> <node> <value>"
- exit 2
- fi
- get_node_id() {
- if [[ "$1" == @* ]]; then
- echo $1
- return
- fi
- pw-dump | jq --arg DESCR "$1" --arg CLASS "$2" '.[]
- | select(.info.props["media.class"] == $CLASS)
- | select(.info.props["node.description"] == $DESCR)
- | .id'
- #pw-dump | jq -r --arg CLASS "Audio/Sink" --arg DESCR "$descr" "$jq_filter"
- }
- format_volume() {
- local s="$1"
- case "$s" in
- +*) # leading plus
- printf "%s%%+\n" "${s#+}" ;;
- -*) # leading minus
- printf "%s%%-\n" "${s#-}" ;;
- *) # no sign
- printf "%s%%+\n" "$s" ;;
- esac
- }
- case "$action" in
- "set-volume")
- id=$(get_node_id $node "Audio/Sink")
- volume=$(format_volume $value)
- # echo "id $id of node $node -> $volume"
- if [ -n $id ]; then
- wpctl set-volume -l 1.0 $id $volume
- fi
- ;;
- "set-mute")
- id=$(get_node_id $node "Audio/Sink")
- #echo "id $id of node $node"
- wpctl set-mute $id $value
- status=$(wpctl get-volume $id | grep -o 'MUTED')
- if [ -z "$status" ]; then
- echo -e "OPEN"
- else
- echo -e "MUTED"
- fi
- ;;
- *)
- echo "Unknown command: $value"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment