MacBook Air/Pro: run script upon lid close?
There does not seem to be a way for a program to get notified when the lid is closed. However, the state of the lid can be monitored periodically (and in this particular case, every second) and actions taken based on the lid state.

I do not know of any program that can provide a complete solution for your need, but you can use the following information to build a solution yourself.


Download this clamshellstate.pl perl script
You can run it in Terminal (under /Applications/Utilities) like:  

./clamshellstate.pl 1  


to get an output like "Open" or "Closed" indicating the current lid state
Create a shell script like (substitute script-to-run with a shell script you'd like to run):  

./clamshellstate.pl 1 | grep Closed &gt; /dev/null &amp;&amp; *script-to-run*

Configure this script to run once every second using launchd.plist. Or use Lingon to easily configure launchd.plist.


Note: Instead of clamshellstate.pl, you can also use the following command in Terminal:

ioreg -r -k AppleClamshellState | grep '"AppleClamshellState" = Yes' | cut -f2 -d"="


to get a "Yes" for the closed state and a "No" for the open state.