I’m an avid xmonad user, and I’ve recently switched over to conky +
dzen as my status bar. A recent issue I had is with getting Dropbox
status information into my conky.

I did some hacking and here’s the result. I love the way it turned out:

This is a pretty generic approach on adding anything into conky +
dzen. Here’s the steps I took:

1. Write some scripts to produce the text you want #

Conky has methods to run arbitrary scripts and echo their
output. This abstraction makes it easy to get the text you want.

I started writing a couple shell scripts that get me the info I need:

Note: I used the Dropbox command line tool to get this info. You'll
need that installed. on arch, it's the 'dropbox-cli' package.








<span class="c1"># drobox-down</span>
<span class="c1"># echos the Dropbox download speed</span>
<span class="c1">#!/usr/bin/env bash</span>

<span class="nv">status</span><span class="o">=</span><span class="sb">`</span>dropbox status <span class="p">|</span> grep Downloading<span class="sb">`</span>
<span class="nv">SYNC_REGEX</span><span class="o">=</span><span class="s2">"([0-9,]+) KB/sec"</span>

<span class="o">[[</span> <span class="nv">$status</span> <span class="o">=</span>~ <span class="nv">$SYNC_REGEX</span> <span class="o">]]</span>
<span class="nv">download_speed</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">BASH_REMATCH</span><span class="p">[1]</span><span class="si">}</span><span class="s2">"</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$download_speed</span> !<span class="o">=</span> <span class="s2">""</span> <span class="o">]]</span> <span class="p">;</span> <span class="k">then</span>
  <span class="nb">echo</span> <span class="s2">"</span><span class="nv">$download_speed</span><span class="s2"> KB/sec"</span>
<span class="k">fi</span>











<span class="c1"># drobox-up</span>
<span class="c1"># echos the Dropbox upload speed</span>
<span class="c1">#!/usr/bin/env bash</span>

<span class="nv">status</span><span class="o">=</span><span class="sb">`</span>dropbox status <span class="p">|</span> grep Uploading<span class="sb">`</span>
<span class="nv">SYNC_REGEX</span><span class="o">=</span><span class="s2">"([0-9,]+) KB/sec"</span>

<span class="o">[[</span> <span class="nv">$status</span> <span class="o">=</span>~ <span class="nv">$SYNC_REGEX</span> <span class="o">]]</span>
<span class="nv">upload_speed</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">BASH_REMATCH</span><span class="p">[1]</span><span class="si">}</span><span class="s2">"</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$upload_speed</span> !<span class="o">=</span> <span class="s2">""</span> <span class="o">]]</span> <span class="p">;</span> <span class="k">then</span>
  <span class="nb">echo</span> <span class="s2">"</span><span class="nv">$upload_speed</span><span class="s2"> KB/sec"</span>
<span class="k">fi</span>











<span class="ch">#!/usr/bin/env bash</span>
<span class="c1"># Dropbox-files</span>
<span class="c1"># lists a single filename if only a single file is being synced</span>
<span class="c1"># otherwise, echos the number of files synced</span>

<span class="nv">status</span><span class="o">=</span><span class="sb">`</span>dropbox status <span class="p">|</span> grep Syncing<span class="sb">`</span>
<span class="nv">SYNC_REGEX</span><span class="o">=</span><span class="s2">"([0-9,]+) files remaining"</span>
<span class="nv">FILENAME_REGEX</span><span class="o">=</span><span class="s1">'"(.*)"'</span>

<span class="o">[[</span> <span class="nv">$status</span> <span class="o">=</span>~ <span class="nv">$SYNC_REGEX</span> <span class="o">]]</span>
<span class="nv">files_remaining</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">BASH_REMATCH</span><span class="p">[1]</span><span class="si">}</span><span class="s2">"</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$files_remaining</span> <span class="o">==</span> <span class="s2">""</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then</span>

    <span class="o">[[</span> <span class="nv">$status</span> <span class="o">=</span>~ <span class="nv">$FILENAME_REGEX</span> <span class="o">]]</span>
    <span class="nv">filename</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">BASH_REMATCH</span><span class="p">[1]</span><span class="si">}</span><span class="s2">"</span>
    <span class="nb">echo</span> <span class="nv">$filename</span>

<span class="k">else</span>
    <span class="nb">echo</span> <span class="s2">"</span><span class="nv">$files_remaining</span><span class="s2"> files"</span>
<span class="k">fi</span>

Now to get that cool Dropbox icon in there. The thing to note about
conky + dzen specifically is that you can’t pipe images into your bar
(as far as I know, someone please correct me here). You’re left with the
options of xbm files, which are bitmap descriptions.

Luckily, it’s not too hard to generate your own. Gimp, the Photoshop of Linux,
can save into xbm files for you. Simply open it up, export it, and you’re done!

Note: make sure to export the xbm to fit the size of your bar. I
couldn't find a way of telling conky to scale the image (which makes
sense, conky is just piping output dzen so it has no way of knowing
the height). My bar is about 16 pixels high, so I exported 16
pixels.

You can also download the xbm I created if you’d like: my Dropbox xbm

3. Add them to your conky script #

Now that we have our shell scripts, and our icons, you can execute them in your conky
script. I got the arrows from the nice icon set.
If you’re lazy you can also get them from my rc files.

Once you have all your assets, add in the relevant pieces into your conky:

out_to_console yes
out_to_x no
update_interval <span class="m">1</span>

lua_load <span class="nv">$HOME</span>/.xmonad/conky_scripts/conky_lua_scripts.lua

<span class="c1"># note: Dropbox needed dropbox-cli on arch</span>

TEXT
<span class="c1"># ---- START DROPBOX STUFF ---</span>
^fg<span class="o">(</span><span class="se">\#</span>007ee5<span class="o">)</span> ^i<span class="o">(</span><span class="nv">$HOME</span>/.xmonad/icons/Dropbox.xbm<span class="o">)</span> <span class="se">\</span>
<span class="c1"># ---- description of files changing ---</span>
^fg<span class="o">(</span><span class="se">\#</span>FFFF00<span class="o">)</span> <span class="si">${</span><span class="nv">execi</span><span class="p"> 6 </span><span class="nv">$HOME</span><span class="p">/.xmonad/conky_scripts/Dropbox-files</span><span class="si">}</span> ^fg<span class="o">()</span><span class="se">\</span>
<span class="c1"># ---- download speed info ---</span>
^fg<span class="o">(</span><span class="se">\#</span>8888FF<span class="o">)</span> ^i<span class="o">(</span><span class="nv">$HOME</span>/.xmonad/icons/net_down_03.xbm<span class="o">)</span> <span class="si">${</span><span class="nv">execi</span><span class="p"> 6 </span><span class="nv">$HOME</span><span class="p">/.xmonad/conky_scripts/Dropbox-down</span><span class="si">}</span> ^fg<span class="o">()</span> / <span class="se">\</span>
<span class="c1"># ---- upload speed info ---</span>
^fg<span class="o">(</span><span class="se">\#</span>AA0000<span class="o">)</span> ^i<span class="o">(</span><span class="nv">$HOME</span>/.xmonad/icons/net_up_03.xbm<span class="o">)</span> <span class="si">${</span><span class="nv">execi</span><span class="p"> 6 </span><span class="nv">$HOME</span><span class="p">/.xmonad/conky_scripts/Dropbox-up</span><span class="si">}</span> ^fg<span class="o">()</span> <span class="se">\</span>

Notes:

  • I changed the colors with ^fg(#COLOR_HASH)

  • to split your conky on multiple lines, I use the delimiter ‘'

And there you go! You have a nice, clean Dropbox activity bar.