polybar: Custom script no longer works

I have this custom module to get the current song from Spotify.

[module/spotify]
type = custom/script
exec = ~/.config/polybar/spotify
interval = 2

This is the script:

#!/bin/bash
if [ "$(playerctl status)" = "Playing" ]; then
  title=`exec playerctl metadata xesam:title`
  artist=`exec playerctl metadata xesam:artist`
  echo "$title - $artist"
else
  echo ""
fi

Polybar version is: polybar 2.5.0-4-g2cde3f3-git Now, after rebooting today, the module no longer works at all. The script still works, but the module no longer shows an output in my polybar.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 48 (16 by maintainers)

Most upvoted comments

Just for posterity’s sake, the comment above ^ has nothing to do with the underlying cause of this issue (even if it has the same symptoms).

So, I’ve encountered this “no output” issue myself, but I’m using zsh, not fish. Running polybar via sh solves the issue, too:

SHELL=$(which sh) polybar

I’ve updated my polybar launch script to use that, and it’s resolved the issue permanently. There’s likely something carrying over from the zsh/fish shells that’s impacting how polybar itself is spawning processes (or the environment in which those processes run). Even launching polybar outside of a terminal window (via i3, or a launcher like rofi or dmenu) causes problems (although in those scenarios, I would get terminal: tabs: no such device or address as the script output in polybar). I start X manually after logging in, which is again, via a virtual console running zsh, so part of me still thinks it’s the non-bash shell causing issues.

@jaagr for completeness’ sake, here’s the output of those commands you requested:

$ echo $SHELL
$ /usr/bin/zsh
$ test -x /bin/sh; echo $?
$ 0

Let me know if there’s anything else I can help with. If this is just a caveat that’s required going forward, it’s probably worth updating the custom/script section of the wiki so that non-standard shell users don’t get tripped up. 🙂

It’s /usr/bin/fish, however that shouldn’t make any difference because "/usr/bin/env sh -c [command]"is how polybar executes scripts, and I have declared the shell to run under with the hashbang.