Run Script When Screen Dims and Undims


I have a couple of applescripts (actually, they’re just executing terminal commands) that trigger an X-10 module to turn a desk lamp on and off. I have it in my speakable items and can turn the light on and off with voice commands. But, I think it would be better if the light could turn off when the screen dims after inactivity and turn back on when I wake the screen up. (I don’t let the computer go to sleep, just dim the screen.)

Is it possible to trigger an applescript, automator action, or terminal command when these events occur?

Thanks for any help or advice anyone can provide.


dimming is controlled by pmset – look at man pmset in Terminal. I think you’d have to poll something to figure it out.

You might do better by polling for the idle time (the time since there was keyboard or trackpad input). For example, this script by StefanK might be modified to your ends:

	set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F); print $idle,\"\";last}'")
	if (idleTime begins with "<") then set idleTime to (do shell script "perl -e 'printf(hex(\"" & (text 2 thru -2 of idleTime) & "\"))'") as number
	set idleTime to idleTime / 1.0E+9
	display dialog idleTime as string giving up after 5 default button "cancel" -- press enter or click cancel to escape the loop.
end repeat