Advertisement
Guest User

Untitled

a guest
Jun 14th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. #!/bin/bash
  2. ## Connects an A2DP device using d-bus and pulsaudio ##
  3. ## Add your info to the varibles below, don't foreget to make the script executable ##
  4. ## For use on Ubuntu 10.04, Version 1.1 ##
  5. ## Created 08/08/2010 by Allan Branch, modified 12/07/10 ##
  6. ## Thanks to hohlraum from ubuntuforums.org for the Karmic fix! ##
  7. ## http://ubuntuforums.org/showpost.php?p=10206634&postcount=44 ##
  8. ## Ubuntu 9.10 can use this script, but must install pulseaudio-module-bluetooth ##
  9. ## and load module-bluetooth-discover using pactl load-module module-bluetooth-discover ##
  10.  
  11. ## Copyright Allan Branch, Distributed under the terms of the GNU General Public License ##
  12.  
  13. ## This program is free software: you can redistribute it and/or modify ##
  14. ## it under the terms of the GNU General Public License as published by ##
  15. ## the Free Software Foundation, either version 3 of the License, or ##
  16. ## (at your option) any later version. ##
  17. ## ##
  18. ## This program is distributed in the hope that it will be useful, ##
  19. ## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
  20. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
  21. ## GNU General Public License for more details. ##
  22. ## ##
  23. ## You should have received a copy of the GNU General Public License ##
  24. ## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
  25.  
  26. ## User Dependent Items ##
  27.  
  28. ## Use "pactl list | grep bluez_source" to find source when device is connected ##
  29. ## Use "pactl list | grep alsa_output" to find sink ##
  30. ## Run: ##
  31. ## adapter_device=`dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | grep /org/bluez | awk '{printf$3}'| sed 's/\"//g'` ##
  32. ## Then: ##
  33. ## dbus-send --system --print-reply --dest=org.bluez $adapter_device org.bluez.Adapter.ListDevices | grep /org/bluez ##
  34. ## To find a device with the matching bluetooth address to yours ##
  35. ## Type the dev_XX_XX_XX_XX_XX_XX part in the script at your_device=YOURDEVICE ##
  36.  
  37. audio_source=YOURSOURCE
  38. audio_sink=YOURSINK
  39. your_device=YOURDEVICE
  40.  
  41. ## End of User Dependent Items ##
  42.  
  43. ## 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.
  44.  
  45. adapter_device=`dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | grep /org/bluez | awk '{printf$3}'| sed 's/\"//g'`
  46. 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`
  47.  
  48. a2dp_connect ()
  49. {
  50. dbus-send --system --print-reply --dest=org.bluez $device org.bluez.AudioSource.Connect | zenity --progress --title="Bluetooth Audio" --text="Now Connecting"
  51. pactl load-module module-loopback source=$audio_source sink=$audio_sink > ~/.bluetooth_unload
  52. zenity --warning --title="Bluetooth Audio" --text="Finished"
  53. }
  54. a2dp_disconnect ()
  55. {
  56. dbus-send --system --print-reply --dest=org.bluez $device org.bluez.AudioSource.Disconnect > /dev/null
  57. number="`cat ~/.bluetooth_unload`"
  58. pactl unload-module $number
  59. rm ~/.bluetooth_unload
  60. }
  61. REPLY=$(zenity --list --title="Bluetooth Audio Stream" --text="What would you like to do?" --column="check" --column="Action" --radiolist \
  62. true "Connect Bluetooth Audio" \
  63. false "Disconnect Bluetooth Audio" \
  64. );
  65. if [ "$REPLY" == "Connect Bluetooth Audio" ]; then
  66. if [ -e ~/.bluetooth_unload ]; then
  67. zenity --question --title="Bluetooth Audio" --text="Already Connected, \nDo you want to attempt to reconnect?"
  68. if [ $? -eq 0 ]; then
  69. a2dp_disconnect;
  70. a2dp_connect;
  71. else
  72. dbus-send --system --print-reply --dest=org.bluez $device org.bluez.AudioSource.Disconnect > /dev/null
  73. zenity --warning --title="Bluetooth Audio" --text="Quitting Script\nPlease re-run script to reconnect"
  74. fi
  75. else
  76. a2dp_connect;
  77. fi
  78. else
  79. if [ "$REPLY" == "Disconnect Bluetooth Audio" ]; then
  80. if [ -e ~/.bluetooth_unload ]; then
  81. zenity --question --title="Bluetooth Audio" --text="Are you sure you want to disconnect?"
  82. if [ $? -eq 0 ]; then
  83. a2dp_disconnect;
  84. zenity --warning --title="Bluetooth Audio" --text="Finished"
  85. else
  86. zenity --warning --title="Bluetooth Audio" --text="Quitting Script"
  87. fi
  88. else
  89. zenity --warning --title="Bluetooth Audio" --text="Already Disconnected"
  90. fi
  91. else
  92. zenity --warning --title="Bluetooth Audio" --text="Quitting Script"
  93. fi
  94.  
  95. fi
  96. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement