Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## Connects an A2DP device using d-bus and pulsaudio ##
- ## Add your info to the varibles below, don't foreget to make the script executable ##
- ## For use on Ubuntu 10.04, Version 1.1 ##
- ## Created 08/08/2010 by Allan Branch, modified 12/07/10 ##
- ## Thanks to hohlraum from ubuntuforums.org for the Karmic fix! ##
- ## http://ubuntuforums.org/showpost.php?p=10206634&postcount=44 ##
- ## Ubuntu 9.10 can use this script, but must install pulseaudio-module-bluetooth ##
- ## and load module-bluetooth-discover using pactl load-module module-bluetooth-discover ##
- ## Copyright Allan Branch, Distributed under the terms of the GNU General Public License ##
- ## This program is free software: you can redistribute it and/or modify ##
- ## it under the terms of the GNU General Public License as published by ##
- ## the Free Software Foundation, either version 3 of the License, or ##
- ## (at your option) any later version. ##
- ## ##
- ## This program is distributed in the hope that it will be useful, ##
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
- ## GNU General Public License for more details. ##
- ## ##
- ## You should have received a copy of the GNU General Public License ##
- ## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
- ## User Dependent Items ##
- ## Use "pactl list | grep bluez_source" to find source when device is connected ##
- ## Use "pactl list | grep alsa_output" to find sink ##
- ## Run: ##
- ## adapter_device=`dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | grep /org/bluez | awk '{printf$3}'| sed 's/\"//g'` ##
- ## Then: ##
- ## dbus-send --system --print-reply --dest=org.bluez $adapter_device org.bluez.Adapter.ListDevices | grep /org/bluez ##
- ## To find a device with the matching bluetooth address to yours ##
- ## Type the dev_XX_XX_XX_XX_XX_XX part in the script at your_device=YOURDEVICE ##
- audio_source=YOURSOURCE
- audio_sink=YOURSINK
- your_device=YOURDEVICE
- ## End of User Dependent Items ##
- ## D-BUS keeps changing the path for qdbus on reboot, this finds what the path is at the moment // This is hohlraum fix for Karmic, therefore it theoretically should work on all versions of Ubuntu.
- adapter_device=`dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | grep /org/bluez | awk '{printf$3}'| sed 's/\"//g'`
- device=`dbus-send --system --print-reply --dest=org.bluez $adapter_device org.bluez.Adapter.ListDevices | grep /org/bluez | awk '{printf$3}'| sed 's/\"//g'| grep $your_device`
- a2dp_connect ()
- {
- dbus-send --system --print-reply --dest=org.bluez $device org.bluez.AudioSource.Connect | zenity --progress --title="Bluetooth Audio" --text="Now Connecting"
- pactl load-module module-loopback source=$audio_source sink=$audio_sink > ~/.bluetooth_unload
- zenity --warning --title="Bluetooth Audio" --text="Finished"
- }
- a2dp_disconnect ()
- {
- dbus-send --system --print-reply --dest=org.bluez $device org.bluez.AudioSource.Disconnect > /dev/null
- number="`cat ~/.bluetooth_unload`"
- pactl unload-module $number
- rm ~/.bluetooth_unload
- }
- REPLY=$(zenity --list --title="Bluetooth Audio Stream" --text="What would you like to do?" --column="check" --column="Action" --radiolist \
- true "Connect Bluetooth Audio" \
- false "Disconnect Bluetooth Audio" \
- );
- if [ "$REPLY" == "Connect Bluetooth Audio" ]; then
- if [ -e ~/.bluetooth_unload ]; then
- zenity --question --title="Bluetooth Audio" --text="Already Connected, \nDo you want to attempt to reconnect?"
- if [ $? -eq 0 ]; then
- a2dp_disconnect;
- a2dp_connect;
- else
- dbus-send --system --print-reply --dest=org.bluez $device org.bluez.AudioSource.Disconnect > /dev/null
- zenity --warning --title="Bluetooth Audio" --text="Quitting Script\nPlease re-run script to reconnect"
- fi
- else
- a2dp_connect;
- fi
- else
- if [ "$REPLY" == "Disconnect Bluetooth Audio" ]; then
- if [ -e ~/.bluetooth_unload ]; then
- zenity --question --title="Bluetooth Audio" --text="Are you sure you want to disconnect?"
- if [ $? -eq 0 ]; then
- a2dp_disconnect;
- zenity --warning --title="Bluetooth Audio" --text="Finished"
- else
- zenity --warning --title="Bluetooth Audio" --text="Quitting Script"
- fi
- else
- zenity --warning --title="Bluetooth Audio" --text="Already Disconnected"
- fi
- else
- zenity --warning --title="Bluetooth Audio" --text="Quitting Script"
- fi
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement