Demand Compliance from the Cisco VPN Client using Applescript and Quicksilver on Mac OS X

I have an Airport Express that I use, aside from basic network connectivity, for streaming music and printing with my Powerbook. Several months ago I started noticing that all of these things would periodically stop working. The first time it happened I thought the Airport Express had just glitched and needed to be reset. For some reason, this reset normally fixed my problem. But there was that rare occassion when no amount of hardware resets and network voodoo fixed the problem. After a while I realized that it might be a problem with my VPN client. From time to time I need to use a Cisco VPN client to connect to resources made available by my university or my program. After some poking around I found the daemon, killed it, and restored sanity to my network setup.

Cisco VPN Client

It turns out that even though the Cisco VPN client requires you to load a horribly designed GUI application while you are connected to the network, it also loads a daemon on startup. (I assume this is for some basic firewall functionality, but I don’t know for sure.) There is also no user interface provided by the client GUI to start or stop this daemon. Which is problamatic, because sometimes the client itself complains that the daemon hasn’t been loaded. Of course, it also doesn’t tell you that definitively. It just complains about “error fffffffffffffch”.

Cisco VPN Client Error Screen

You can manually stop, start, and restart this daemon using a relatively well-behaved unix application.
To start:
sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN start
To stop:
sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN stop
To restart:
sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart

For a while this is how I controlled the daemon from misbehaving. I soon got tired of that nonsense and decided to automate the process using a bit of Applescript inspired by Scott Russell’s script and make it accessible from Quicksilver.

Here are the scripts:

Start CiscoVPN:
do shell script "sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart" with administrator privileges
if result does not contain "loaded successfully" then
if result does not contain "already loaded" then
display alert "There was an error starting the Cisco VPN service. '" & result & "'" as warning giving up after 10
end if
end if
do shell script "sudo -k"

Stop CiscoVPN:
do shell script "sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN stop" with administrator privileges
if result does not contain "succeeded" then
display alert "There was an error stopping the Cisco VPN service. The Cisco VPN may already be stopped.'" & result & "'" as warning giving up after 10
end if
do shell script "sudo -k"

Restart CiscoVPN:
do shell script "sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart" with administrator privileges
if result does not contain "loaded successfully" then
display alert "There was an error restarting the Cisco VPN service." as warning buttons {"OK"} default button "OK" giving up after 10
end if
do shell script "sudo -k"

At this point, if you’re a super Unix hacker you should be asking yourself, “why don’t I just make a shell script and throw it somewhere in my path?” The answer to this is pure aesthetics. With this Applescript you can invoke it with Quicksilver and have it ask you for your password using a dialog box that should be familiar to anyone that has ever tried making any system changes. Then if, for some reason, the script errors out, the error is presented in a familiar dialog box. You can probably do the same thing with pyObjC or something else, but Applescript does the job here.

Now that you’re convinced Applescript is the one and only solution, throw these into descriptively named files such as “Restart CiscoVPN.scpt” and copy them into your script folder. This “Scripts” folder can be found in the “Library” folder, which itself if found in your home directory. Now all you need to do is tell Quicksilver to look for scripts in this folder. Now all thats left is to make sure Quicksilver is cataloguing that directory. (Here’s a quick tutorial on Quicksilver in case you don’t have it installed yet.)

What we need to do to check this is to verify the catalogue settings in the Quicksilver preferences. You can do this several different ways, the easiest probably by clicking the Quicksilver menubar item (that may or may not be active on your system) and clicking on “Preferences …”. Click on the “Catalog” item in the left pane. Make sure Modules > Scripts > Scripts (User) is checked (assuming that you put your scripts into “~/Library/Scripts”. Refer to the image if this isn’t clear.

Quicksilver Preferences

That’s it. Let me know if this doesn’t work for you. Chances are that if you aren’t using the same version of Mac OS X (10.4), Quicksilver (B36), or Cisco VPN Client (4.6.03) this will not work flawlessly.

CiscoVPN Daemon Vanquisher (4.45 KB)