You are not logged in.

#1 2015-01-26 20:12:44

Mapl3
Member
Registered: 2015-01-26
Posts: 2

[Solved] JSON if statement

So I'm trying to configure i3 with conky and want to know if my volume is on or not. The JSON I'm using is

{"full_text": ${if_match ${exec amixer get Master | grep "%" | cut -d' ' -f8}=[off]}"OFF" ,"color":"\#dc322f"},
{"full_text": "${else}"},
{"full_text": ${if_match ${exec amixer get Master | grep "%" | cut -d' ' -f8}=[on]}"ON" ,"color":"\#dc322f"},
{"full_text": "${endif}${endif}"},

But no matter what the value is the first satement (OFF) is only showed. What am I doing wrong with the if satement?

SOLUTION:

saf1 wrote:

from man conky:

...
if_match expression
...
              stringArgument is enclosed in quotation marks (")
              Valid operands are: '>', '<', '>=', '<=', '==', '!='.
...

so the ${if_match} statement in your code should look like this:

${if_match "${exec amixer get Master | sed -n '/%/s/^.*\[\(.*\)\]$/\1/gp'}" == "off"}
    ...
 ${else}
    ${if_match "${exec amixer get Master | sed -n '/%/s/^.*\[\(.*\)\]$/\1/gp'}" == "on"}
        ...
    ${endif}
${endif}

HTH.

Last edited by Mapl3 (2015-01-27 00:20:43)

Offline

#2 2015-01-26 21:49:59

saf1
Member
Registered: 2011-04-04
Posts: 28

Re: [Solved] JSON if statement

from man conky:

...
if_match expression
...
              stringArgument is enclosed in quotation marks (")
              Valid operands are: '>', '<', '>=', '<=', '==', '!='.
...

so the ${if_match} statement in your code should look like this:

${if_match "${exec amixer get Master | sed -n '/%/s/^.*\[\(.*\)\]$/\1/gp'}" == "off"}
    ...
 ${else}
    ${if_match "${exec amixer get Master | sed -n '/%/s/^.*\[\(.*\)\]$/\1/gp'}" == "on"}
        ...
    ${endif}
${endif}

HTH.

Last edited by saf1 (2015-01-26 22:08:05)

Offline

#3 2015-01-27 00:19:46

Mapl3
Member
Registered: 2015-01-26
Posts: 2

Re: [Solved] JSON if statement

saf1 wrote:

from man conky:

...
if_match expression
...
              stringArgument is enclosed in quotation marks (")
              Valid operands are: '>', '<', '>=', '<=', '==', '!='.
...

so the ${if_match} statement in your code should look like this:

${if_match "${exec amixer get Master | sed -n '/%/s/^.*\[\(.*\)\]$/\1/gp'}" == "off"}
    ...
 ${else}
    ${if_match "${exec amixer get Master | sed -n '/%/s/^.*\[\(.*\)\]$/\1/gp'}" == "on"}
        ...
    ${endif}
${endif}

HTH.

Worked like a charm. Though I did try with '=='.

Offline

Board footer

Powered by FluxBB