Skip to content

Instantly share code, notes, and snippets.

@smasty
Created June 27, 2011 19:29
Show Gist options
  • Save smasty/1049607 to your computer and use it in GitHub Desktop.
Save smasty/1049607 to your computer and use it in GitHub Desktop.
Keyboard LED Gmail checker
#!/usr/bin/env php
<?php
/**
* Checks your GMail for unread messages and lets your keyboard LED diod blink if there are some.
*
* (c) Martin Srank (http://smasty.net)
* Licensed under the MIT License - http://opensource.org/licenses/mit-license
* Use at your own risk. Tested on Debian Squeeze.
*/
// Gmail credentials
$user = 'username';
$pswd = 'password';
// Config options
$interval = 300; // Interval for checking e-mail state (in seconds)
$ledID = '3'; // Keyboard LED ID
$blinkCount = 8; // Number of LED blinks
$blinkSpeed = 0.2 // LED blink speed (in seconds)
while(true){
$atom = file_get_contents("https://$user:$pswd@mail.google.com/mail/feed/atom");
if(preg_match('~\<fullcount\>(\d+)\<\/fullcount\>~i', $atom, $match) && $match[1] > 0){
for($i = 0; $i < $blinkCount; $i++){
`xset -led $ledID`;
usleep($blinkSpeed * 1e6);
`xset led $ledID`;
usleep($blinkSpeed * 1e6);
}
}
sleep($interval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment