#!/bin/sh # This script will pop up a dialog whenever a device was found or lost. # You can use this as a template for your own device discovery job. # # When this script is called by kbluetoothd, there will be several # special environment variables defined: # # $FOUND_DEVICES: # This is a list of bluetooth device addresses of all devices # which have been detected since the last invocation of the script. # $LOST_DEVICES: # These are the devices which were reachable during the last run, # but have disappeared in the meantime. # $CURRENT_DEVICES: # This is complete list of devices which are reachable at the moment. # $JOB_PATH: # The full path name of the currently running script # $JOB_DIR: # The directory in the user's home directory where the jobs are stored # $JOB_TEMPLATE_DIR: # The directory containing the job templates # # This script will be called with one single parameter: # "run": The script should be executed # "configure": Lets the user configure the script. case "$1" in run) # Look up the name for each found/lost device with the # device name cache of kbluetoothd via dcop FOUND=" " for dev in $FOUND_DEVICES ; do FOUND="$FOUND $(dcop kbluetoothd DeviceNameCache getCachedDeviceName $dev)" done LOST=" " for dev in $LOST_DEVICES ; do LOST="$LOST $(dcop kbluetoothd DeviceNameCache getCachedDeviceName $dev)" done # Display a notification dialog for the found/lost devices with kdialog if [ "$FOUND" != " " ] ; then kdialog \ --yesno "Found headset: $FOUND ($FOUND_DEVICES). Run bluetooth-alsa daemon (btsco)?" \ --title "Found headset" ret=$? if [ $ret -eq 0 ]; then btsco -s -f "$FOUND_DEVICES" else kdialog --msgbox "You should run bluetooth-alsa daemon manually, otherwise you cannot use this headset." fi fi if [ "$LOST" != " " ] ; then kdialog --msgbox "Lost devices:$LOST" --title "Lost devices" fi ;; configure) # Simply run kedit let the user edit this script. # A more sophisticated solution might use kdialog to hide # the shell script from the user kedit "$JOB_PATH" ;; esac