Author Topic: Script to turn light on when you are using your Mac and turn off when idle  (Read 822 times)


  • Guru
  • ****
  • Posts: 431
    • View Profile
Here is a script you can run on your apple mac. It gets the idle time, so your workstation light is kept on when you are working but turned off when you go away. I'm working on a few more scripts which I will tidy up and put into the Wiki a little later. I'm working on one to control your AV equipment when you are listening to music in iTunes.

Note you must add your Macs public RSA key (ssh-keygen -t rsa) to the LMCE /root/.ssh/authorized_keys for this to work, which may be considered to be a security hole, depending on how secure your mac is. It would be better to get MessageSend running on the Mac but I couldn't manage it.

Code: [Select]


## Do not change anything below here ##

while true ; do

idle=`ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle;last}' | sed 's/\..*//'`
if [ $idle -gt $timeout ] ; then
 if [ $status -eq 1 ] ; then
  ssh root@$dcerouter "/usr/pluto/bin/MessageSend localhost $lamp $lamp 1 193" && status=0 && echo "Lamp turned off"
  if [ $status -eq 0 ] ; then
    ssh root@$dcerouter "/usr/pluto/bin/MessageSend localhost $lamp $lamp 1 192" && status=1 && echo "Lamp turned on"
sleep 2