dustinrue/ControlPlane — Issue #138: Use AC Charger Serial Number as evidence.
Author: mendepie
Created: 2012-02-27 04:39:58+00:00
State: open

I have a laptop that I use in a number of locations, and I want to detect when I am sitting at my desk. I can't use WiFi, IP, or network link since they are not unique at different locations. I don't always plug in USB, so i can't detect something unique off of that.

My thought is to use the Serial Number of the AC charger as an evidence (as displayed in System Profiler > Hardware > Power > Ac Charger Information.

I've doing this with a shell script

#!/bin/sh
expected="0x00979ef5"
seen="$(system_profiler -xml SPPowerDataType | \
grep -A1 -m1 sppower_ac_charger_serial_number | \
tail -1)"
exec [ "$expected" = "$(echo $seen)" ]

While this is working, it is a hack, and there is an overhead of running a script on such a frequent basis.