Created
October 13, 2025 21:39
-
-
Save Dregu/aa748bebc7c3aeddd3ceb55c0f046c5d to your computer and use it in GitHub Desktop.
Set active window volume/toggle mute in Hyprland with pactl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [[ -z "$1" ]]; then | |
echo "Set active window volume/toggle mute in Hyprland with pactl" | |
echo "Usage: $(basename "$0") -5%|+5%|toggle" | |
exit 0 | |
fi | |
# gather data | |
ACTIVE=$(hyprctl -j activewindow) | |
INPUTS=$(pactl -fjson list sink-inputs) | |
# try to find media matching window title first, e.g. individual browser tab | |
TITLE=$(echo "$ACTIVE"|jq -r .title) | |
TITLE=${TITLE% —*} | |
QUERY=".[]|select(.properties[\"media.name\"] == \"$TITLE\").index" | |
INDEXES=$(echo "$INPUTS"|jq -r "$QUERY") | |
if [[ ! -z "$INDEXES" ]]; then | |
for INDEX in $INDEXES; do | |
if [ "$1" == "toggle" ]; then | |
pactl set-sink-input-mute $INDEX toggle | |
else | |
pactl set-sink-input-volume $INDEX "$@" | |
fi | |
done | |
else | |
# no media matching window title, fallback to all media matching pid | |
PID=$(echo "$ACTIVE"|jq -r .pid) | |
QUERY=".[]|select(.properties[\"application.process.id\"] == \"$PID\").index" | |
INDEXES=$(pactl -fjson list sink-inputs|jq -r "$QUERY") | |
for INDEX in $INDEXES; do | |
if [ "$1" == "toggle" ]; then | |
pactl set-sink-input-mute $INDEX toggle | |
else | |
pactl set-sink-input-volume $INDEX "$@" | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment