One of the really powerful features of Virtual Box is that it lets you start VMs in a headless mode. You can connect to the VMs using RDP or just let them run in the background and do their job. The problem with running a lot of VMs in headless mode is trying to determine which VMs are running and when I want to shutdown the VM, I have to go to the command line and do a VBoxManage controlvm VM_NAME acpipowerbutton. This can get really tedious.

To simplify the most common interactions I do with my VMs, I built a simple Notification Area applet in Python. I started with this great tutorial that I found after doing some Google searches, Gnome Notification Area Application in Python. This is a great starting point for building applets for the Notification Area.

When I right click on my notification applet, I want it to bring up a popup menu with all of my VMs. I wrote the following Python function to list VirtualBox VMs:

def listVMs(type):
  f = os.popen('VBoxManage list ' + type)
  lines = f.readlines()
  vms = []
  for line in lines:
    vms.append(line[1:line.rfind('"')])
  f.close()
  return vms

VBoxManage list can list all kinds of interesting things in VirtualBox but I only care about vms to list all the VMs and runningvms to list all the running VMs. I then use these lists to populate the popup menu with options for shutting down running VMs and options for starting non-running VMs in normal mode or in headless mode.

When I click on my icon in the Notification Area, I want it to either start the VirtualBox Manager or focus the VirtualBox Manager window if it is already running. Starting the VirtualBox Manager is easy. Determining if the VirtualBox Manager is already running and focusing its window is much more difficult. I found wmctrl which allows me to focus windows based on their title and I’m able to leverage this in my applet.

The script I’m using in its entirety is available at vbox-notification-app.py.