Script to turn on/off device if unread mail (gmail)

Moderator: Telldus

Script to turn on/off device if unread mail (gmail)

Postby eirikh » Tue Feb 16, 2010 5:49 pm

Got a gmail account? Here is a simple script to turn on/off a device if you have unread email:

Replace "5" with your device id .. :)

checkEmail.sh:
Code: Select all
#!/bin/bash
RET=`curl -u username@gmail.com:password --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "1" if /<(fullcount)>[^0]<\/\1>/;'`

if [ $RET == "1" ] ; then
 tdtool --on 5
else
 tdtool --off 5
fi


crontab:
Code: Select all
*/4 * * * * ~/checkEmail.sh &> /dev/null

(check every 4 minutes)
eirikh
 
Posts: 25
Joined: Sat Dec 19, 2009 7:31 am

Postby tom_rosenback » Tue Feb 16, 2010 7:08 pm

Sweet script :D Have to put this behind the ear :P
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
tom_rosenback
 
Posts: 767
Joined: Tue Aug 05, 2008 9:37 pm


Return to Mac OS X

Who is online

Users browsing this forum: No registered users and 1 guest