Guest User

Untitled

a guest
Feb 24th, 2026
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.43 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. action="$1"
  4. node="$2"
  5. value="$3"
  6.  
  7. # Validate there's an argument
  8. if [ -z "$value" ]; then
  9.     echo "Usage: $0 <set-volume|set-mute> <node> <value>"
  10.     exit 2
  11. fi
  12.  
  13. get_node_id() {
  14.     if [[ "$1" == @* ]]; then
  15.         echo $1
  16.         return
  17.     fi
  18.  
  19.     pw-dump | jq --arg DESCR "$1" --arg CLASS "$2" '.[]
  20.        | select(.info.props["media.class"] == $CLASS)
  21.        | select(.info.props["node.description"] == $DESCR)
  22.        | .id'
  23.    
  24.     #pw-dump | jq -r --arg CLASS "Audio/Sink" --arg DESCR "$descr" "$jq_filter"
  25. }
  26.  
  27. format_volume() {
  28.   local s="$1"
  29.   case "$s" in
  30.     +*)  # leading plus
  31.       printf "%s%%+\n" "${s#+}" ;;
  32.     -*)  # leading minus
  33.       printf "%s%%-\n" "${s#-}" ;;
  34.     *)   # no sign
  35.       printf "%s%%+\n" "$s" ;;
  36.   esac
  37. }
  38.  
  39. case "$action" in
  40.     "set-volume")
  41.         id=$(get_node_id $node "Audio/Sink")
  42.         volume=$(format_volume $value)
  43.         # echo "id $id of node $node -> $volume"
  44.         if [ -n $id ]; then
  45.             wpctl set-volume -l 1.0 $id $volume
  46.         fi
  47.         ;;
  48.  
  49.     "set-mute")
  50.         id=$(get_node_id $node "Audio/Sink")
  51.         #echo "id $id of node $node"
  52.         wpctl set-mute $id $value
  53.         status=$(wpctl get-volume $id | grep -o 'MUTED')
  54.         if [ -z "$status" ]; then
  55.             echo -e "OPEN"
  56.         else
  57.             echo -e "MUTED"
  58.         fi
  59.         ;;
  60.     *)
  61.         echo "Unknown command: $value"
  62.         ;;
  63. esac
Advertisement
Add Comment
Please, Sign In to add comment