How to Tell When the Laptop Lid is Closed

@Alexander's Shell Script line answers the "lid closed" issue, but I've discovered that still doesn't solve my probem, so I've asked the next question in a separate thread: