I have been writing a bash script for the radiotray-ng applet, fine tuning it through a mountain of trial and error, and I would like it to simply exit the script cleanly after accomplishing this.
It is supposed to return the status of the app, whther its running, playing, or not running.
Here is the code.
#!/bin/bash
app="radiotray-ng"
launchrt="/usr/bin/radiotray-ng --play"
playrt=".config/radiotray-ng/rtng-dbus play"
rtstate=$(.config/radiotray-ng/rtng-dbus get_player_state | grep state)
playing=$(.config/radiotray-ng/rtng-dbus get_player_state | grep state | grep playing)
running=$(.config/radiotray-ng/rtng-dbus get_player_state | grep state | grep running)
notrunning=$(.config/radiotray-ng/rtng-dbus get_player_state | grep state | grep Error)
echo $rtstate > /dev/null
if [[ $rtstate = $playing ]]; then
echo "RadioTray Is Playing"
else
if [[ $rtstate = $running ]]; then
echo "RadioTray Is Running. Starting Player"
$playrt
else
if [[ $rtstate = $notrunning ]]; then
echo "RadioTray Is Not Running. Launching Player"
$launchrt
fi
fi
fi
exit 0
This is what I get when it's playing:
RadioTray Is Playing
Not playing but still running (launched):
RadioTray Is Stopped. Starting Player
At this point it connects to the stream and exits the script cleanly.
And not running at all (exited):
Error org.freedesktop.DBus.Error.ServiceUnknown: The name com.github.radiotray_ng was not provided by any .service files (4X) RadioTray Is Not Running. Launching Player
Then it plays. It then hangs until I exit the app, which does so cleanly and without any error messages.
I would like it to return the status of the player (not running, running but not playing, or playing), and exit cleanly. Clearly, this happens now in two of the three possible outcomes. I would like it to perform this every time, if at all possible. I realize it may not be.
The assistance is very appreciated.