View Single Post
Old 10-20-2024, 05:55 AM   #1
neil_swann80
0000000000101010
neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.neil_swann80 ought to be getting tired of karma fortunes by now.
 
neil_swann80's Avatar
 
Posts: 5,891
Karma: 12981955
Join Date: Mar 2023
Location: An island off the coast of Ireland
Device: PB632 [HD3]
script to enable BT and launch audio apps

I use my PocketBook frequently to play audiobooks and occasionally to listen to MP3s (mainly background noise) whilst reading.
I regularly pair two different sets of BT headphones as well as my car stereo to the Pocketbook.
I find it cumbersome to use the PocketBook menu system to connect across these devices, so wrote a shell script to automate the procedure.
  • The script checks if BT is active, if not it will enable it.
  • The Bluetootth settings page is launched to allow a specific device to be paired.
  • A dialog box then prompts the user to launch the Audiobook or Media player app.
  • Once the audio app is closed, if the script enabled BT it will disable it.

Save the code below as a .app file in /mnt/ext1/applications if you'd like to try it. May need a device reboot before it shows in User's section of the app menu.
Spoiler:
Code:
#!/bin/sh
appDir=/ebrmain/cramfs/bin
BTstatus=$(netagent bt status | grep -o BT_STATE_OFF)
BTisPaired=/sys/class/bluetooth/hci0/hci0:1

if [ $BTstatus == BT_STATE_OFF ]; then initialBT=off; netagent bt on
else initialBT=on; fi

function onExit {
  if [ $initialBT == off ]; then netagent bt off; fi
}
trap onExit 0

function pairBT {
  $appDir/settings.app -o bluetooth
  if [ -d $BTisPaired ]; then :
  else pairBT_dialog; fi
}

function pairBT_dialog {
  $appDir/dialog 3 "" "No BT device connected!" "Try again" "Ignore" "Exit"; ans=$?
  if [ $ans == 2 ]; then :
  elif [ $ans == 3 ]; then exit
  else pairBT; fi
}

function startApps {
  $appDir/dialog 2 "" "Which Audio App?" "Audiobook" "MP3 Player" "Exit"; ans=$?
  if [ $ans == 1 ]; then $appDir/audio_books.app
  elif [ $ans == 2 ]; then $appDir/music_player.app
  elif [ $ans == 3 ]; then exit
  else startApps; fi
}

pairBT
startApps
exit

Last edited by neil_swann80; 10-23-2024 at 12:47 PM. Reason: Improved code
neil_swann80 is offline   Reply With Quote