AnyBar and SuperDuper!

For years I’ve been using a combination of this script (or its predecessor) and GeekTool to let me know whether my nightly SuperDuper! backup was successful. It works fine, printing a short summary of the backup log file onto the upper left corner of my Desktop screen.

Old SuperDuper summary

I’ve always thought, though, that there’s a better, less obtrusive way to let me know if the backup failed.1

Today, One Thing Well posted an article on a utility called AnyBar, written by Nikita Prokopov, that lets you put a colored dot in your menubar by sending your computer a UDP message. As soon as I read the article, I knew I could make some use of it.

There has to be something I can use this for: github.com/tonsky/AnyBar
Dr. Drang (@drdrang) Apr 7 2015 12:54 PM

Justin Scholz rang the bell:

@drdrang hey cool, will be my new “my custom backup scripts” indicator light ;-)
Justin Scholz (@JMoVS) Apr 7 2015 1:12 PM

Instead of putting a bunch of words on my Desktop, I could just put a colored dot in my menubar—green for a successful backup, red for a failure.

It turned out to be pretty simple. Although I know next to nothing about compiling Mac programs, I downloaded and unzipped the AnyBar repository, opened it in Xcode, and built the app without incident. I moved it into my /Applications directory and used the Users & Groups System Preference to make it one of my login items.

When you first start AnyBar, it puts a hollow circle in your menubar. You can then test it out by running commands like this in the Terminal:

echo -n "purple" | nc -4u -w0 localhost 1738

This one sends a “purple” message to UDP port 1738 on your computer and should turn the hollow circle into a solid purple dot. To turn in back to the hollow white circle, do this:

echo -n "white" | nc -4u -w0 localhost 1738

The AnyBar README on GitHub tells you all the messages you can send and different ways you can customize both the image in the menubar and the UDP port that AnyBar listens to.

With AnyBar working, I took my sdsummary script and rewrote parts of it to use Python’s socket library to send a “red” or “green” message to AnyBar depending on the contents of the latest SuperDuper! log file. Here’s the new script, called sdsignal:

python:
 1:  #!/usr/bin/python
 2:  
 3:  import os
 4:  import socket
 5:  
 6:  # Where the SuperDuper! log files are.
 7:  logdir = (os.environ["HOME"] +
 8:            "/Library/Application Support/" +
 9:            "SuperDuper!/Scheduled Copies/" +
10:            "Smart Update Backup from Macintosh HD.sdsp/Logs/")
11:  
12:  # AnyBar communication info.
13:  abhost = '127.0.0.1'
14:  abport = 1738
15:  
16:  # Get the last log file.
17:  logfiles = [x for x in os.listdir(logdir) if x[-5:] == 'sdlog']
18:  logfiles.sort()
19:  lastlog = logdir + logfiles[-1]
20:  
21:  # Look for the "Copy complete" line.
22:  good = False
23:  with open(lastlog) as f:
24:    for line in f:
25:      if "| Info | Copy complete." in line:
26:        good = True
27:        break
28:  
29:  # Send AnyBar the green or red signal depending on whether the backup worked.
30:  # AF_INET is for IPv4 and SOCK_DGRAM is for UDP.
31:  anybar = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
32:  anybar.connect((abhost, abport))
33:  if good:
34:    anybar.send('green')
35:  else:
36:    anybar.send('red')

Lines 7–10 define the folder where the log files are. They’re named according to the date on which they’re generated, so it’s easy to find the latest one by sorting them and choosing the last one. That’s what Lines 17–19 do.

Lines 22–27 scan through the log file, looking for a particular string that appears near the end of the file when the backup has been successful. A Boolean variable called good is set according to whether than string is found.

Lines 31–36 use the socket library to send the appropriate signal. Line 31 creates the socket using IPv4 and UDP. Line 32 connects the socket to the localhost (127.0.0.1) at port 1738. The host and port numbers we need to communicate with AnyBar are set in Lines 13–14. Lines 33–36 then send the appropriate signal.

Because last night’s backup was successful, this is what I got when I ran sdsignal:

SuperDuper signal in menubar

I have Bartender running, so I can put the AnyBar dot wherever I want. I’m not sure this is where I’m going to keep it.

Of course, the point of all this is to have sdsignal run automatically sometime after the backup is done. This could be done through the launchd system, but I think it’s simpler to have SuperDuper! do it through a setting in the advanced options pane.

SuperDuper! advanced options

I suspect this isn’t the end of my messing around with AnyBar. One thing I feel certain I’ll do is create new images to use as my SuperDuper! signal. As I said earlier, AnyBar lets you use you own customized menubar icons, and I’d like to have something a little more expressive than a simple dot.


  1. It almost never does, because SuperDuper is quite reliable. I had some problems once when an old backup drive was starting to fail, and I’ve occassionally seen errors when the backup drive didn’t get mounted.