Mac Sudden Motion Sensor: Obtaining activation state
The Sudden Motion Sensor state is available through IOKit.

An open source library, SMSLib, provides an Objective-C interface and sample command line tool for accessing the state of the Sudden Motion Sensor:


  SMSLib is the software library used by SeisMac and SeisMaCalibrate to access the Sudden Motion Sensors in recent Macintosh laptops. Written in Objective-C, it provides easy and stable access, abstracting hardware differences across eleven different models of laptop. For better accuracy, you can use SeisMaCalibrate to calibrate your laptop's Sudden Motion Sensors. SMSLib is open source, released under the University of Illinois/NCSA Open Source License.


Additional sample code and tools are available on Amit Singh's Sudden Motion Sensor page.

A relevant technical question was asked on StackOverflow about this topic, Polling the accelerometer/motion sensor in a MacBook Pro.