From kde-devel Sun May 29 11:56:13 2005 From: Andy Pieters Date: Sun, 29 May 2005 11:56:13 +0000 To: kde-devel Subject: [cross-post] My contribution: a volume cli utility Message-Id: <200505291356.20985.andy () vlaamse-kern ! com> X-MARC-Message: https://marc.info/?l=kde-devel&m=111736785903546 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============0860774274==" --===============0860774274== Content-Type: multipart/signed; boundary="nextPart1368147.N4UAZYO9Rl"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1368147.N4UAZYO9Rl Content-Type: multipart/mixed; boundary="Boundary-01=_d3amCJYrxIXadGT" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_d3amCJYrxIXadGT Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi all I made a little utility that alows you to bind shortcut keys to volume up,= =20 volume down, volume mute, and volume unmute. It does this by executing dcop calls to Kmix I hope this will be of use to someone. With kind regards Example usage: volume --up=20 increases volume with 10% volume --down 20 decreases volume with 20% volume --volume prints current volume level volume --volume 55 sets volume level to 55% volume --mute=20 saves volume level to temporary file and set volume to 0 volume --unmute loads volume level from temporary file and set volume (defaults to 55%) =2D-=20 Registered Linux User Number 379093 =2D- --BEGIN GEEK CODE BLOCK----- Version: 3.1 GAT/O/>E$ d-(---)>+ s:(+)>: a--(-)>? C++++$(+++) UL++++>++++$ P-(+)>++ L+++>++++$ E---(-)@ W+++>+++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++) PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+) e>++++$@ h++(*) r-->++ y--()>++++ =2D- ---END GEEK CODE BLOCK------ =2D- Check out these few php utilities that I released under the GPL2 and that are meant for use with a=20 php cli binary: =20 http://www.vlaamse-kern.com/sas/ =2D- =2D- --Boundary-01=_d3amCJYrxIXadGT Content-Type: application/x-shellscript; name="volume" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="volume" #!/bin/bash # Access Kmix volume trough scripting EXITCODE_HELP=5 EXITCODE_ERROR=1 PROG_NAME='volume' PROG_AUTHOR='Straight-A-Software' PROG_EMAIL='x_terminat_or_3@yahoo.fr' PROG_VERSION='2.0' BASE=`basename $0` TEMPFILE="$HOME/.volume.sh" function end { unset -f end error shorthelp info help morehelp dcopinit getvolume setvolume unset -f loadvolume mute unmute volume up down unset -v PROG_NAME PROG_VERSION PROG_AUTHOR BASE PROG_EMAIL XVALUE XVOLUME TEMPFILE VOLUME #default to exitcode 0 EXITCODE=0 if [ $# -gt 0 ]; then if [ -n $1 ]; then EXITCODE=$1 fi fi if [ $# -gt 1 ]; then if [ -n "$2" ]; then echo "$2" fi fi exit $EXITCODE } function error { if [ $# -gt 0 ]; then end $EXITCODE_ERROR "$1" fi end $EXITCODE_ERROR } function shorthelp { #this function is a trademark of Straight-A-Software #used in conjunction with 'myscripts' utility echo "Access Kmix volume trough cli" end $EXITCODE_HELP } function info { echo "$PROG_NAME v$PROG_VERSION (c) $PROG_AUTHOR Released under the GPL2" echo "$PROG_EMAIL" echo "" } function help { info echo "Access Kmix's volume trough command line interface." echo "Get, set, save volume" echo echo "Usage: $BASE --help | --shorthelp | --morehelp --version --info" echo " $BASE --mute | --unmute | --up [xx] | --down [xx] | --volume [xxx]" echo "" end $EXITCODE_HELP } function morehelp { info echo "Note: this program depends on Kmixer. Install it with the KdeMultimedia " echo "package." echo "" echo "When you --mute, it will try to save a temporary file in your home directory" echo "to save the mastervolume so that when you use --unmute, the volume level will" echo "be at the same level as before." echo "" echo "If no temporary file is found when using --unmute, then the volume level will " echo "be set to 55%" echo "" echo "The name of the temporary file is ~.volumelevel.sh" echo "This file is removed after using --unmute" echo "" echo "When using --up, or --down, it defaults to 10% change unless specified otherwise" echo end $EXITCODE_HELP } function dcopinit { type dcop >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Error dcop not found!" fi #dcop found, try to call it dcop >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Dcop cannot start!" fi #try kmix dcop "kmix" >/dev/null 2>&1 if [ $? -gt 1 ]; then #kmix is NOT running type dcopstart > /dev/null 2>&1 if [ $? -gt 0 ]; then #cannot use dcopstart, try to start it manually type kmix >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Cannot find Kmix!" fi kmix >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Cannot start Kmix!" fi else dcopstart kmix >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Dcop server cannot start Kmix!" fi fi sleep .5 #alow kmix to start fi #see if kmix has a mastervolume dcop kmix Mixer0 masterVolume >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Kmixer does not have a mastervolume!" fi } function getvolume { temp=$(dcop kmix Mixer0 masterVolume 2>&1) if [ $? -eq 0 ]; then XVOLUME=$temp return fi error "Problem retrieving volume!" } function setvolume { VOLUME=55 #default if [ $# -gt 0 ]; then if [ $1 -ge 0 ]; then VOLUME=$1 fi if [ $1 -gt 100 ]; then VOLUME=100 fi fi dcop kmix Mixer0 setMasterVolume $VOLUME >/dev/null 2>&1 if [ $? -gt 0 ]; then error "Problem setting volume!" fi } function savevolume { getvolume echo "echo '$XVOLUME'" >"$TEMPFILE" 2>&1 if [ -f "$TEMPFILE" ]; then chmod +x "$TEMPFILE" 2>&1 fi } function loadvolume { XVOLUME=55 if [ -x "$TEMPFILE" ]; then XVOLUME=$("$TEMPFILE") if [ $XVOLUME -lt 0 ]; then XVOLUME=0 elif [ $XVOLUME -gt 100 ]; then XVOLUME=100 fi rm -rf "$TEMPFILE" > /dev/null 2>&1 fi } function mute { savevolume setvolume 0 end } function unmute { loadvolume setvolume $XVOLUME end } function volume { SET=0 if [ $# -gt 0 ]; then if [ -n $1 ]; then if [ $1 -gt -1 ]; then SET=1 fi fi fi if [ $SET -eq 1 ]; then XVOLUME=$1 if [ $XVOLUME -gt 100 ]; then XVOLUME=100 fi setvolume $XVOLUME end fi getvolume echo $XVOLUME end } function up { INC=10 if [ $# -gt 0 ]; then if [ $1 -gt 0 ]; then INC=$1 fi fi getvolume INC=$[$XVOLUME + $INC] if [ $INC -gt 100 ]; then INC=100 fi setvolume $INC end } function down { DEC=10 if [ $# -gt 0 ]; then if [ $1 -gt 0 ]; then DEC=$1 fi fi getvolume DEC=$[$XVOLUME - $DEC] if [ $DEC -lt 0 ]; then DEC=0 fi setvolume $DEC end } #process command line arguments if [ $# -eq 0 ]; then help fi XVALUE=-1 if [ $# -gt 1 ]; then if [ -n $2 ]; then XVALUE=$2 fi fi case $1 in --volume) dcopinit volume $XVALUE ;; --up) dcopinit up $XVALUE ;; --down) dcopinit down $XVALUE ;; --mute) dcopinit mute ;; --unmute) dcopinit unmute ;; --help) help ;; --shorthelp|--info) shorthelp ;; --morehelp) morehelp ;; --version) info end $EXITCODE_HELP ;; esac help --Boundary-01=_d3amCJYrxIXadGT-- --nextPart1368147.N4UAZYO9Rl Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBCma3kc7EayKyip4URAm7/AJ401k+Xk0yJ1ork/S6eDv0PcfvaPQCffs+J GVS2dsvbEipWpOFj0KaICu4= =9ku9 -----END PGP SIGNATURE----- --nextPart1368147.N4UAZYO9Rl-- --===============0860774274== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --===============0860774274==--