Solved i3bar + Conky (JSON): quotation mark outputs.



I am using i3bar with with sysutils/conky with a JSON wrapper as here. It is working as expected but sometimes it breaks when audio/musicpd is playing some music where the title have "quotation marks".

Removing the quotation marks from the music tags are not an option as I have a huge collection of classical music what the titles often have quotation marks, and I manage them using audio/picard.

I would like to know if there is a way to have those quotation marks not interpreted as JSON?

I found out I could use something like \" to do that but it would just work with static text, and not random ones.

The relevant part of the conky configuration is this:

{ "full_text" : " ${if_match "${mpd_status}" == "Playing"}$mpd_smart - $mpd_elapsed$else${mpd_status}$endif " },

EDIT: the perfect alternative would be py3status but it is not in ports, and all my tentatives to port something resulted in garbage. :)

However port it should be simple and I may try to do later, specially if I do not find solution.

EDIT: polybar is even cooler but also not in ports.

Thank you.
How musicpd supplies data? You could pipe its output through sed to replace bad symbols, e.g. . . . | sed 's/"/=/g'.
(Of course, I used the equal sign as an example, you can find a good unicode symbol to replace with).
I am using the conky built-in mpd module (mpd_status) to pipe the data, I don't know how it work indeed.

I will try to make it using sed, otherwise I will try to port py3status.

I think I could use «» instead.


EDIT: it seem will work using ncmpcpp:

ncmpcpp --current-song | sed 's/"/=/g'
(3:44) Heitor Villa-Lobos - Choros no. 3, W206 =Pica-Pau=

This script worked fine


Ncmpcpp() {
        NCMPCPP=$(ncmpcpp "--current-song")

        echo -n "$NCMPCPP"

echo "$(Ncmpcpp)" | sed 's/"/=/g'

with this conky configuration:
{ "full_text" : " ${execi 2 /home/alex/Scripts/} " },

Now I just need to make the output a bit more "fancy".

Thank you! :beer::beer::beer::beer::beer:
I did a small "improvement" on the sed command and now it output without the need of have a real substitution:

sed 's/"/\\\"/g'

As I found early, if \" but sometimes \\\" (I do not know why one sometimes work and the another not) is used, JSON pass the correct " without interpret it.

substituting " per \\\" in sed worked great because it does not alter the output, just make " to not be parsed as a JSON syntax, and so not interpreted - like that " was a verbatim text.

In other words, it now displays " in the musicpd output correctly.
At the and I used audio/mpc instead of audio/ncmpcpp because I couldn't find a way to modify the ncmpcpp --current-song output. The options available in the man page didn't work for me.

I am leaving it here in case of someone looking for the same in the future.

MPC_FORMAT="%artist% - %title%"

Mpc() {
        MPC_CURRENT=$(mpc current -f "$MPC_FORMAT" -h $MPD_HOST -p $MPD_PORT)

        echo -n "$MPC_CURRENT"

echo "$(Mpc)" | sed 's/"/\\\"/g'

conkyrc-i3bar (relevant part)
{ "full_text" : " ${if_match "${mpd_status}" == "Playing"}${execi 1 /home/alex/Scripts/} ($mpd_elapsed)$else${mpd_status}$endif " },