LinuxMCE Forums
May 18, 2013, 11:52:42 pm GMT-1 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Rule #1 - Be Patient - Rule #2 - Don't ask when, if you don't contribute - Rule #3 - You have coding skills - LinuxMCE's small brother is available: http://www.agocontrol.com
 
   Home   Help Search Chat Login Register  
Pages: [1]
  Print  
Author Topic: Script to turn light on when you are using your Mac and turn off when idle  (Read 367 times)
chrisbirkinshaw
Guru
****
Posts: 431


View Profile
« 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:
#!/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



Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!