#!/bin/sh ################################################################################# # kmixremote - control kmix from a script. # # Set volume # Get volume # Mute ################################################################################# qdbusbin="false" usage() { echo "Usage:" echo "List mixers # $0 list" echo "List controls # $0 list " echo "Get Volume # $0 get [--master | ]" echo "Set Volume # $0 set [--master | ] <0..100>" echo "Mute/Unmute # $0 mute [--master | ] true|false" echo } exit_with_error() { echo "Error: $1" echo usage exit 1 } # Prints the mixer DBUS ID's on the console. leaving out the "/Mixers/" prefix listMixers() { $qdbusbin org.kde.kmix /Mixers org.freedesktop.DBus.Properties.Get org.kde.KMix.MixSet mixers | cut -f3 -d/ errorCode=$? if test $errorCode != 0; then echo "Error $errorCode listing mixers. KMix is not running." fi } # Prints the mixer control DBUS ID's of the given mixer on the console. leaving out the "/Mixers/" prefix listControls() { $qdbusbin org.kde.kmix $1 org.freedesktop.DBus.Properties.Get org.kde.KMix.Mixer controls | cut -f4 -d/ errorCode=$? if test $errorCode != 0; then echo "Error $errorCode listing controls. KMix is not running." fi } command="" qdbuskatie="$(basename @QT_QDBUS_EXECUTABLE@)" if type $qdbuskatie >/dev/null 2>&1 ; then qdbusbin="$qdbuskatie" elif type qdbus >/dev/null 2>&1 ; then qdbusbin="qdbus" else exit_with_error "$0 requires qdbus, but it cannot be found. Please install or check \$PATH" fi # Read args while true; do arg=$1 if test -z "$arg"; then break fi shift if test "x--master" = "x$arg"; then mixer="$($qdbusbin org.kde.kmix /Mixers org.kde.KMix.MixSet.currentMasterMixer)" control="$($qdbusbin org.kde.kmix /Mixers org.kde.KMix.MixSet.currentMasterControl)" elif test "x--help" = "x$arg" -o "x-h" = "x$arg"; then usage exit 0 else # If not a specific option, then interpret as standad args, in this order: command, mixer, control and genericArg if test -z "$command"; then command=$arg elif test -z "$mixer"; then mixer="${arg}" elif test -z "$control"; then control=$arg elif test -z "$genericArg"; then genericArg=$arg else exit_with_error "Too many aguments" fi fi #echo $arg done if test -z "$command"; then usage echo " - The mixer to use. Select one from the following list:" echo "-----------------------------------------------------------------" listMixers exit 0 elif test "xlist" = "x$command"; then if test -z "$mixer"; then listMixers else # List controls listControls "/Mixers/${mixer}" fi exit 0 fi # All following commands require a mixer if test -z "$mixer"; then exit_with_error " argument missing" fi if test -z "$control"; then exit_with_error " argument missing" fi # All following commands require a mixer and a control targetControl="/Mixers/${mixer}/${control}" #echo "ARGS: $command $targetControl $genericArg" # --- EXECUTE PHASE -------------------------------------------------------------------------------------------------- if test "xget" = "x$command"; then # GET $qdbusbin org.kde.kmix $targetControl org.freedesktop.DBus.Properties.Get org.kde.KMix.Control volume elif test "xset" = "x$command"; then # SET $qdbusbin org.kde.kmix $targetControl org.freedesktop.DBus.Properties.Set org.kde.KMix.Control volume $genericArg elif test "xmute" = "x$command"; then # MUTE $qdbusbin org.kde.kmix $targetControl org.freedesktop.DBus.Properties.Set org.kde.KMix.Control mute $genericArg else exit_with_error "No such command '$command'" fi exit 0