WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Simple script for volume up, down or mute using ossmix vol  (Read 3967 times)

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Simple script for volume up, down or mute using ossmix vol
« on: December 09, 2009, 12:41:27 PM »
I wrote this for use with JWM tray buttons, but it might be useful in other contexts.
volume upo

Code: [Select]
#!/bin/sh
# jwmossvol  adjust sound volume up or down or mute using ossmix vol
#            Initially written for use with JWM tray buttons but
#            possibly useful in other contexts.  Lee Muller 20091209
#  ARGS:
#    ${1} = "up" makes sound louder
#         = "dn" makes sound quieter
#         = "mute" if current sound level is non zero, backs up value and
#                  sets it to zero.  Otherwise restores previous value.
#                  If restoring and no previous value saved, set to 50
#
volstore=/tmp/jwmossvol.txt
steppct=5

vol=`ossmix vol |cut -d: -f2`

if [ "${1}" = "up" ] ; then {
  vol=`expr ${vol} \+ ${steppct}`
  if [ ${vol} -gt 100 ] ; then {
    vol=100
  } fi
} fi

if [ "${1}" = "dn" ] ; then {
  vol=`expr ${vol} \- ${steppct}`
  if [ ${vol} -lt 0 ] ; then {
    vol=0
  } fi
} fi

if [ "${1}" = "mute" ] ; then {
  if [ "${vol}" = "0" ] ; then {
    # restore volume
    if [ -f ${volstore} ] ; then {
      vol=`head -1 ${volstore}`
      rm ${volstore}
    } else {
      vol=50
    } fi
  } else {
    # store volume and set to zero
    echo ${vol} >${volstore}
    vol="0"
  } fi
} fi
ossmix vol ${vol} >/dev/null

32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar