You are not logged in.

#1 2014-05-12 09:30:32

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

[conky] removing empty spaces of empty variables [solved]

Hi there,

I am using the following TEXT to display my information:

TEXT
  dropbox [${exec dropbox status | awk 'FNR==1 {print tolower($1)}'}] \
  insync [${exec insync get_status | awk 'FNR==1 {print tolower($1)}'}] \
  crashplan [${exec systemctl status crashplan.service | grep Active: | awk '{print $2}'}] \
  ${exec basename $(ps -efa | grep thunderbird |grep -v 'grep ' | awk '{print $8}')} \
  ${exec basename $(ps -efa | grep zotero |grep -v 'grep ' | awk '{print $8}')} \
  ${exec basename $(ps -efa | grep skype |grep -v 'grep ' | awk '{print $8}')} \
  to-do [${exec cat ~/.todo.md | awk 'NR==1 {print substr( $0, 0, 60 )}'}] ... \
  $alignr ${battery BAT0} \
  SSID: ${wireless_essid wls1} [${wireless_link_qual_perc wls1}%] \
  Volume: ${exec amixer -c 0 get Master | grep Mono: | awk '{print $(NF-2)}'} ${exec amixer -c 0 get Master | grep Mono: | awk '{print $NF}'} \
  Keyboard: ${exec xkb-switch} \
  ${time %H:%M} \
  ${time %a %d %b %Y} 

Some variables such as to display whether Zotero or Skype is running, are not always actually returning an output. Thus, if they are not running, I just get an empty space in my bar:

6QwoHHG.png

Is it possible in Conky, to hide these variables if they return no output to avoid the empty spaces?

Thanks ahead!

Last edited by orschiro (2014-05-14 18:23:58)

Offline

#2 2014-05-12 09:39:47

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [conky] removing empty spaces of empty variables [solved]

Unrelated: awk and grep is redundant:

exec amixer -c 0 get Master | awk '/Mono/ {print $(NF-2)}'

And awk takes filename(s) as an argument, which eliminates the feline:

exec awk 'NR==1 {print substr( $0, 0, 60 )}' ~/.todo.md

No idea about the blanks, though...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-05-12 09:52:42

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: [conky] removing empty spaces of empty variables [solved]

Try the if_running option.

See the conky manpage for details.

Offline

#4 2014-05-14 12:51:17

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [conky] removing empty spaces of empty variables [solved]

@jasonwryan

Thanks, appreciated!

exec awk 'NR==1 {print substr( $0, 0, 60 )}' ~/.todo.md

This works great.

exec amixer -c 0 get Master | awk '/Mono/ {print $(NF-2)}'

Regarding this, I have troubles to only print only the first line. Where would I add NR==1?

I am only interested in the output [43%] and not:

~ exec amixer -c 0 get Master | awk '/Mono/ {print $(NF-2)}'
Playback
[43%]

x33a

Thanks for the hint to if_running. I solved it now the following way:

${if_running thunderbird}${exec basename $(ps -efa | grep thunderbird |grep -v 'grep ' | awk '{print $8}')} [up] ${else}tb [down]$endif \
  ${if_running zotero}${exec basename $(ps -efa | grep zotero |grep -v 'grep ' | awk '{print $8}')} [up]${else}zotero [down]$endif \
  ${if_running skype}${exec basename $(ps -efa | grep skype |grep -v 'grep ' | awk '{print $8}')} [up]${else}skype [down]$endif \

Result:

txVoJFB.png

Offline

#5 2014-05-14 16:45:44

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: [conky] removing empty spaces of empty variables [solved]

I don't know why you are doing all the ps, grep, awk magic. Is it just to get the process name?

If so, you can use the following for the same:

${if_running thunderbird}thunderbird [up] ${else}tb [down]$endif \

Last edited by x33a (2014-05-14 16:46:06)

Offline

#6 2014-05-14 18:23:27

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [conky] removing empty spaces of empty variables [solved]

@x33a

You are absolutely right. I thought too complicated. tongue

This is the solution I am using for now.

Thanks to both of you!

TEXT
  dropbox [${exec dropbox status | awk 'FNR==1 {print tolower($1)}'}] \
  insync [${exec insync get_status | awk 'FNR==1 {print tolower($1)}'}] \
  crashplan [${exec systemctl status crashplan.service | grep Active: | awk '{print $2}'}] \
  ${if_running thunderbird}thunderbird [up] ${else}thunderbird [down]$endif \
  ${if_running skype}skype [up] ${else}skype [down]$endif \
  to-do [${exec awk 'NR==1 {print substr( $0, 0, 70 )}' ~/.todo.md}] ... \
  $alignr ${battery BAT0} \
  SSID: ${wireless_essid wls1} [${wireless_link_qual_perc wls1}%] \
  Volume: ${exec amixer -c 0 get Master | grep Mono: | awk '{print $(NF-2)}'} ${exec amixer -c 0 get Master | grep Mono: | awk '{print $NF}'} \
  Keyboard: ${exec xkb-switch} \
  ${time %H:%M} \
  ${time %a %d %b %Y} 

Offline

#7 2014-05-14 19:01:47

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [conky] removing empty spaces of empty variables [solved]

If you want the percentage, you could filter on that:

awk '/%/ {gsub(/[\[\]]/,""); print $4}' <(amixer sget Master)

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#8 2014-05-15 11:52:19

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [conky] removing empty spaces of empty variables [solved]

Thanks but it leaves the same issue that it returns two lines:

~ awk '/%/ {gsub(/[\[\]]/,""); print $5}' <(amixer sget Master) 
40%
40%

I cannot figure out how to combine your command with the NR==1 parameter to only print the first line.

~ awk 'NR==1 /%/ {gsub(/[\[\]]/,""); print $5}' <(amixer sget Master) 
awk: cmd. line:1: NR==1 /%/ {gsub(/[\[\]]/,""); print $5}
awk: cmd. line:1:        ^ syntax error
awk: cmd. line:1: error: Unmatched ( or \(: / {gsub(/
~ awk '/%/ {gsub(/[\[\]]/,""); print $5 NR==1}' <(amixer sget Master)      
0
0

Offline

#9 2014-05-15 18:06:17

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [conky] removing empty spaces of empty variables [solved]

What is the raw output of `amixer sget Master`?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#10 2014-05-15 18:33:55

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [conky] removing empty spaces of empty variables [solved]

The two percentages are due to the left and right front speaker:

~ amixer sget Master
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 26208 [40%] [on]
  Front Right: Playback 26208 [40%] [on]

Offline

#11 2014-05-15 19:10:31

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [conky] removing empty spaces of empty variables [solved]

Well, assuming you don't care that you only get one channel, tell awk to exit after the first match:

awk '/%/ {gsub(/[\[\]]/,""); print $5; exit}' <(amixer sget Master)

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#12 2014-05-15 19:44:33

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [conky] removing empty spaces of empty variables [solved]

Something odd with Conky here.  Your command works flawlessly in the shell and also exists properly after the first command. However, in conky it leads to no output at all.

TEXT
  ${exec awk '/%/ {gsub(/[\[\]]/,""); print $5; exit}' <(amixer sget Master)} \
  dropbox [${exec dropbox status | awk 'FNR==1 {print tolower($1)}'}] \

P44hOij.png

Do you use Conky yourself and can confirm that?

Offline

#13 2014-05-15 20:07:41

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [conky] removing empty spaces of empty variables [solved]

I don't use conky, but I imagine it uses a POSIX shell, so the process substitution will need to be changed to a pipe (as you are doing with the dropbox command).


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#14 2014-05-16 00:41:35

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [conky] removing empty spaces of empty variables [solved]

Using this displays one channel in conky for me:

${exec amixer sget Master | awk '/%/{}END{gsub(/[\[\]]/,""); print $5}'}

Edit: I had the cached status of the thread, my bad.

Last edited by emeres (2014-05-16 00:48:03)

Offline

#15 2014-05-16 05:44:19

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [conky] removing empty spaces of empty variables [solved]

The pipe was the solution.

Thank you both @jasonwryan and @emeres!

Offline

Board footer

Powered by FluxBB