LinuxMCE Forums

General => Users => Topic started by: chrisbirkinshaw on January 28, 2009, 01:03:06 pm

Title: Script to turn light on when you are using your Mac and turn off when idle
Post by: chrisbirkinshaw on January 28, 2009, 01:03:06 pm
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]
#!/bin/sh

dcerouter="192.168.1.1"
lamp="108"
timeout="60"

## Do not change anything below here ##

status=0
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"
 fi
else
  if [ $status -eq 0 ] ; then
    ssh root@$dcerouter "/usr/pluto/bin/MessageSend localhost $lamp $lamp 1 192" && status=1 && echo "Lamp turned on"
  fi
fi
 
sleep 2

done