1

Im trying to chech if the file exists in conky using ${if_existing ..} as follows:

    ${if_existing /home/stanislav/.cache/yandexweather/bkn_n.png}YES \
    ${else}NO
    ${endif}\

And this works perfectly. However how can I use ${if_existing ..} statement with an output of another command? For Example:

    ${if_existing echo "~/.cache/yandexweather/"$(python ~/.cache/yandexweather/yw_script.py -image_0)}YES \
    ${else}NO
    ${endif}\

The latter doesnt work

RStanislav
  • 48
  • 3

1 Answers1

1

You could use ${eval ...} to have the shell command calculated first, then having the ${if_...} part parsed. For example,

${eval $${if_existing ${execi 10 echo "myfile"}}\
          YES $${else} NO $${endif} }

Inside the eval, the if.. else and endif parts are made to not work by doubling the $ to $$. However, the ${execi part runs and executes the shell command (echo ...) every 10 seconds (choose a big value if your expression will never change).

After the execi has returned the string (myfile, in this example), the resulting command is parsed again. Each $$ has been evaluated to $, so we have:

${if_existing myfile} YES ${else} NO ${endif}
meuh
  • 11,500
  • 2
  • 29
  • 45
  • Well, it seems like a proper way but i still cant get to work the following sentence: `${eval $${if_existing ${exec echo $HOME"/.cache/yandexweather/"$(python ~/.cache/yandexweather/yw_script.py -image_0)}} YES $${else} No $${exec curl -s ${exec python ~/.cache/yandexweather/yw_script.py -image_0_url} -o /home/stanislav/.cache/yandexweather/${exec python ~/.cache/yandexweather/yw_script.py -image_0}} $${endif}}` . Actually I try to check if the file exists, and if not , i want to download it. – RStanislav Aug 26 '19 at 23:04
  • There are problems at startup as conky seems not to run the exec on the first iteration, so you can end up with a syntax error for `if_existing`. I think for something as complicated as you have, you should write a simple shell script to do the whole if..else..endif, and then just call it from conky with `${execi }`. – meuh Aug 27 '19 at 09:15
  • Thank you for your reply. It should be easier to use an additional script. – RStanislav Aug 28 '19 at 05:19