Skip to content

Simpler brightness and volume bar script examples #44

@freddylist

Description

@freddylist

The current brightness and volume bar scripts require a Python installation as well as some Python libraries.
I propose we also suggest some simpler shell scripts with minimal dependencies.

Here are some implementations I've come up with, they work for me but I'm new to shell scripting so there is probably room for improvement:

Brightness bar requires only inotify-tools

#!/bin/sh

# Change below to suit your system
BACKLIGHT="/sys/class/backlight/amdgpu_bl0"
BRIGHTNESS="$BACKLIGHT/brightness"
MAX_BRIGHTNESS=$(cat "$BACKLIGHT/max_brightness")

inotifywait -m -e modify "$BRIGHTNESS" \
  | while IFS= read -r line; do cat $BRIGHTNESS; done \
  | xob -m "$MAX_BRIGHTNESS"

Volume bar requires only alsa-utils
(and optionally Wireplumber with Pipewire)

#!/bin/sh

# Wait for amixer to become available
until [ "$(amixer)" ]; do sleep 0.1; done

# `amixer events` always emits 1 event from the start, so we must skip it
skip=1
stdbuf -oL amixer events |
  while IFS= read -r line; do
    case ${line%%,*} in
      ('event value: numid='[34])
        if [ "$skip" -eq 0 ]; then
          # The `0+$2` below is to remove the '%' sign
          amixer sget Master |
            awk -F'[][]' '/Left:/ {print 0+$2 ($4 == "off" ? "!" : "")}'

          # Using Pipewire/Wireplumber:
          #wpctl get-volume @DEFAULT_AUDIO_SINK@ |
          #  awk '{ gsub(/\./, "", $2); print $2 ($3 == "[MUTED]" ? "!" : "")}'
        else
          skip=$(( skip - 1 ))
        fi
    esac
  done | xob

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions