Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: Lee on December 09, 2009, 09:41:27 AM

Title: Simple script for volume up, down or mute using ossmix vol
Post by: Lee on December 09, 2009, 09:41:27 AM
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