Here is an example Sikuli script that automates connecting to a VPN via a tray icon for me.

Sikuli is at http://groups.csail.mit.edu/uid/sikuli/