aboutsummaryrefslogtreecommitdiff
path: root/extras/HOME
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-01-08 15:49:43 -0700
committerJosh Rahm <joshuarahm@gmail.com>2023-01-08 15:49:43 -0700
commite027c8463b9d46562c5c848bdc36f52e92d98a7b (patch)
treefc839f02f5ce654eb342be9e1dc3bb01b011b441 /extras/HOME
parent760ca866a17105056688da9eaa0829941a91bc76 (diff)
downloadrde-e027c8463b9d46562c5c848bdc36f52e92d98a7b.tar.gz
rde-e027c8463b9d46562c5c848bdc36f52e92d98a7b.tar.bz2
rde-e027c8463b9d46562c5c848bdc36f52e92d98a7b.zip
Make bluetooth-select and spotify-control generic.
spotify-control will now look for the first media player on dbus and control that, rather than rely on stable dbus service names. This is because spotifyd used to have a stable name, but now it doesn't. I can't wait to find out how I shot myself in the foot with this ...
Diffstat (limited to 'extras/HOME')
-rwxr-xr-xextras/HOME/.local/bin/bluetooth-select.sh71
-rwxr-xr-xextras/HOME/.local/bin/spotify-control32
2 files changed, 72 insertions, 31 deletions
diff --git a/extras/HOME/.local/bin/bluetooth-select.sh b/extras/HOME/.local/bin/bluetooth-select.sh
index 4bc416b..d01aa4c 100755
--- a/extras/HOME/.local/bin/bluetooth-select.sh
+++ b/extras/HOME/.local/bin/bluetooth-select.sh
@@ -1,26 +1,73 @@
#!/bin/bash
+run() {
+ out=$("$@" 2>&1)
+ if [ "$?" -ne 0 ] ; then
+ gxmessage "$out"
+ fi
+}
+
+disconnect() {
+ echo "Disconnecting"
+ run bluetoothctl -- disconnect
+}
+
+power_off() {
+ echo "Power Off"
+ run bluetoothctl -- power off
+}
+
+power_on() {
+ echo "Power On"
+ run bluetoothctl -- power on
+}
+
+scan_on() {
+ echo "Scan On"
+ run bluetoothctl -- scan on
+}
+
+scan_off() {
+ echo "Scan Off"
+ run bluetoothctl -- scan off
+}
+
+declare -A ops
+
+ops["Disconnect"]=disconnect
+ops["Power On"]=power_on
+ops["Power Off"]=power_off
+ops["Scan On"]=scan_on
+ops["Scan Off"]=scan_off
+
+ops_keys=""
+for k in "${!ops[@]}" ; do
+ ops_keys="$ops_keys\n$k"
+done
+
+
if [[ -z "$ROFI" ]] ; then
ROFI='rofi -dmenu'
fi
devices="$(bluetoothctl -- devices | sed 's#^Device ##')"
selection="$(
- echo -e "$devices\nDisconnect\nPower On\nPower Off" | $ROFI -i -p "Connect Bluetooth" \
+ echo -e "$devices\n$ops_keys" | $ROFI -i -p "Connect Bluetooth" \
-theme-str '* {theme-color: #8888ff;}' \
-dmenu)"
-macaddr="${selection%% *}"
+if [ -z "${selection}" ] ; then
+ exit 1
+fi
-if [[ "$macaddr" == "Disconnect" ]] ; then
- echo "Disconnecting"
- exec bluetoothctl -- disconnect
-elif [[ "$selection" == "Power On" ]] ; then
- echo "Turning Power On"
- exec bluetoothctl -- power on
-elif [[ "$selection" == "Power Off" ]] ; then
- echo "Turning Power Off"
- exec bluetoothctl -- power off
+echo "selection=${selection}"
+
+op="${ops[$selection]}"
+if [[ -z "$op" ]] ; then
+ macaddr="${selection%% *}"
+ echo "macaddr=${macaddr}"
+ run bluetoothctl -- connect "$macaddr"
+else
+ eval "$op"
fi
-exec bluetoothctl -- connect "$macaddr"
diff --git a/extras/HOME/.local/bin/spotify-control b/extras/HOME/.local/bin/spotify-control
index ac921c7..1bd7bcc 100755
--- a/extras/HOME/.local/bin/spotify-control
+++ b/extras/HOME/.local/bin/spotify-control
@@ -6,17 +6,21 @@ then
exit
fi
-if [ "$(pidof spotifyd)" != "" ]
-then
- target=spotifyd
-else
- target=spotify
-fi
+# Some targets (spotifyd) don't have a stable dbus path.
+target="$( \
+ dbus-send \
+ --print-reply \
+ --dest=org.freedesktop.DBus \
+ /org/freedesktop/DBus org.freedesktop.DBus.ListNames \
+ | sed 's#.*string \"\(.*\)"#\1#' \
+ | grep MediaPlayer2 \
+ | head -n1)"
+
function mpris2_dbus_player_do {
dbus-send \
--print-reply \
- --dest=org.mpris.MediaPlayer2."$target" \
+ --dest="$target" \
/org/mpris/MediaPlayer2 \
"org.mpris.MediaPlayer2.Player.$1"
}
@@ -24,7 +28,7 @@ function mpris2_dbus_player_do {
function mpris2_dbus_get_player_property {
dbus-send \
--print-reply \
- --dest=org.mpris.MediaPlayer2."$target" \
+ --dest="$target" \
/org/mpris/MediaPlayer2 \
org.freedesktop.DBus.Properties.Get \
string:'org.mpris.MediaPlayer2.Player' "string:$1"
@@ -32,17 +36,7 @@ function mpris2_dbus_get_player_property {
case $1 in
"play")
- status="$("$0" getStatus)"
- if [[ "$target" == "spotifyd" ]] ; then
- # Spotifyd doesn't support play/pause
- if [[ "$status" == "Playing" ]] ; then
- "$0" pause
- else
- "$0" justplay
- fi
- else
- mpris2_dbus_player_do PlayPause
- fi
+ mpris2_dbus_player_do PlayPause
;;
"next")
mpris2_dbus_player_do Next