Score:0

Notification using bluetoothctl output

us flag

I am using 22.04 and I created a bash script to disconnect my Bluetooth speaker. You can see the code below

#!/bin/sh
bluetoothctl disconnect macID

notify-send "Soundbar Disconnected!"

While it works great for my needs as I have it as a desktop shortcut, it is a one-click disconnect for me now.

I was wondering whether I can display the output message of the bluetootctl command instead of the predefined text. ie, if there is no speaker connected, the output will be different.

I tried echo blutoothctl.output, which didn't work. Would be nice to have some help here. Thanks.

Score:0
us flag

managed to use a function and then assigned the output to a variable. Then echo and notify-send works

#!/bin/sh

myoutput () {

bluetoothctl disconnect macID

}


myoutput

VAR=$(myoutput)

echo "${VAR} , is the output"

notify-send "${VAR} | Soundbar Disconnected!"
Score:0
ca flag

Terse answer:

$ man bash then type
/Command\ Substitution to find the description for $(...), and
/Special\ Parameters for $?


$ . /etc/os-release; echo $NAME $VERSION  # if that matters
Ubuntu 20.04.6 LTS (Focal Fossa)

$ saved="$(bluetoothctl connect 00:09:DD:10:48:F9)"

$ echo $?
1

$ echo $saved
Attempting to connect to 00:09:DD:10:48:F9 [CHG] Device 00:09:DD:10:48:F9 Connected: yes [CHG] Device 00:09:DD:10:48:F9 ServicesResolved: yes Failed to connect: org.bluez.Error.NotAvailable

$ echo $saved | od -t x1z
0000000 41 74 74 65 6d 70 74 69 6e 67 20 74 6f 20 63 6f  >Attempting to co<
0000020 6e 6e 65 63 74 20 74 6f 20 30 30 3a 30 39 3a 44  >nnect to 00:09:D<
0000040 44 3a 31 30 3a 34 38 3a 46 39 20 5b 01 1b 5b 30  >D:10:48:F9 [..[0<
0000060 3b 39 33 6d 02 43 48 47 01 1b 5b 30 6d 02 5d 20  >;93m.CHG..[0m.] <
0000100 44 65 76 69 63 65 20 30 30 3a 30 39 3a 44 44 3a  >Device 00:09:DD:<
0000120 31 30 3a 34 38 3a 46 39 20 43 6f 6e 6e 65 63 74  >10:48:F9 Connect<
0000140 65 64 3a 20 79 65 73 20 5b 01 1b 5b 30 3b 39 33  >ed: yes [..[0;93<
0000160 6d 02 43 48 47 01 1b 5b 30 6d 02 5d 20 44 65 76  >m.CHG..[0m.] Dev<
0000200 69 63 65 20 30 30 3a 30 39 3a 44 44 3a 31 30 3a  >ice 00:09:DD:10:<
0000220 34 38 3a 46 39 20 53 65 72 76 69 63 65 73 52 65  >48:F9 ServicesRe<
0000240 73 6f 6c 76 65 64 3a 20 79 65 73 20 46 61 69 6c  >solved: yes Fail<
0000260 65 64 20 74 6f 20 63 6f 6e 6e 65 63 74 3a 20 6f  >ed to connect: o<
0000300 72 67 2e 62 6c 75 65 7a 2e 45 72 72 6f 72 2e 4e  >rg.bluez.Error.N<
0000320 6f 74 41 76 61 69 6c 61 62 6c 65 0a              >otAvailable.<
0000334

$
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.