From a8887a7f9ef1330c07a75793d52c5f143b538bba Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 25 Apr 2023 18:16:07 -0400 Subject: [PATCH] mpris-status: Don't fail when no media players are present --- .config/xfce4/panel/scripts/mpris-status.py | 23 ++++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.config/xfce4/panel/scripts/mpris-status.py b/.config/xfce4/panel/scripts/mpris-status.py index 67d0f02..8427972 100755 --- a/.config/xfce4/panel/scripts/mpris-status.py +++ b/.config/xfce4/panel/scripts/mpris-status.py @@ -89,13 +89,16 @@ def status_icon(player: Player) -> str: players = [Player(dbus_interface_info={"dbus_uri": uri}) for uri in get_players_uri()] players.sort(key=status_key) -active_player_id = get_player_id_from_uri(players[0]._dbus_interface_info.uri) -print( - "" - + (f"[{ len(players) }] " if len(players) > 1 else "") - + format_player(players[0], short=True) - + "" -) -print(f"playerctl --player={ active_player_id } play-pause") -print(f"{ status_icon(players[0]) }") -print("" + "\n".join(format_player(player) for player in players) + "") +if len(players) > 0: + active_player_id = get_player_id_from_uri(players[0]._dbus_interface_info.uri) + print( + "" + + (f"[{ len(players) }] " if len(players) > 1 else "") + + format_player(players[0], short=True) + + "" + ) + print(f"playerctl --player={ active_player_id } play-pause") + print(f"{ status_icon(players[0]) }") + print("" + "\n".join(format_player(player) for player in players) + "") +else: + print("No media players")