Skip to content

Instantly share code, notes, and snippets.

@nakamuraos
Last active February 26, 2025 16:47
Show Gist options
  • Save nakamuraos/336eef0e86d6e107136399301bee3ec3 to your computer and use it in GitHub Desktop.
Save nakamuraos/336eef0e86d6e107136399301bee3ec3 to your computer and use it in GitHub Desktop.
Termux GUI: Volume control + Show current volume

Termux GUI / Desktop Environment

Usage

  • Create a folder, for example $HOME/scripts/volume-control
  • Create files with above contents: up.sh, down.sh, mute.sh
  • Add execute perm.: chmod +x *.sh
  • From GUI -> Find program Keyboard -> Tab Application Shortcuts
  • Add 3 shortcuts:
    • /data/data/com.termux/files/home/scripts/volume-control/mute.sh -> AudioMute key
    • /data/data/com.termux/files/home/scripts/volume-control/up.sh -> AudioRaiseVolume key
    • /data/data/com.termux/files/home/scripts/volume-control/down.sh -> AudioLowerVolume key
  • Enjoy!
#!/usr/bin/env bash
# vol down
pactl set-sink-volume @DEFAULT_SINK@ -5%
# get current vol
STATUS=$(pactl list sinks | grep '^[[:space:]]Volume:' | \
head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
# show current vol
notify-send -h int:transient:1 "Volume" "$STATUS%" -t 1500 -r 999999
!/usr/bin/env bash
# mute toggle
pactl set-sink-mute @DEFAULT_SINK@ toggle
# get status mute
STATUS=$(pactl list sinks | grep '^[[:space:]]Mute:' | \
head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([a-z]*\).*,\1,')
# show notify
notify-send -h int:transient:1 "Mute" "$STATUS" -t 1500 -r 999999
#!/usr/bin/env bash
# vol up
pactl set-sink-volume @DEFAULT_SINK@ +5%
# get current vol
STATUS=$(pactl list sinks | grep '^[[:space:]]Volume:' | \
head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
# show current vol
# -t: timeToShow | -r: notifyToReplace
notify-send -h int:transient:1 "Volume" "$STATUS%" -t 1500 -r 999999
@souibes
Copy link

souibes commented Feb 26, 2025

Its only today that I came up with your script. What I did is create a panel in xfce4 with 3 laucchers pointing to your script. Thanks a lot.
Screenshot_20250226-163933_AVNC
I hope the screenshot will be visible. I haven't finished yet

@souibes
Copy link

souibes commented Feb 26, 2025

I know it is a bit of asking too much but my idea would be assign the volume up hardware key to open a sliding volume up and down without the mute fonction. Could you please point me to what would be the steps to achieve that. Thank you again

@nakamuraos
Copy link
Author

@souibes Have a good day 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment