Skip to content

Instantly share code, notes, and snippets.

@vivien
Last active September 11, 2020 09:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivien/0dbbecd0372f808a895c to your computer and use it in GitHub Desktop.
Save vivien/0dbbecd0372f808a895c to your computer and use it in GitHub Desktop.
i3blocks default volume script
#!/bin/sh
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CARD="${1:-0}"
MIXER="${2:-default}" # use pulse for pulseaudio, default is alsa
case $BLOCK_BUTTON in
2) amixer -q sset Master toggle ;; # middle click
4) amixer -q sset Master 10%+ ;; # scroll up
5) amixer -q sset Master 10%- ;; # scroll down
esac
volume () {
amixer -c $CARD -M -D $MIXER get Master
}
format () {
ruby -ne '$_ =~ /\[(\d+)%\] \[(on|off)\]/ and (puts $2 == "off" ? "MUTE" : "#$1%"; exit)'
}
volume | format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment