Created
June 20, 2011 23:29
-
-
Save kenguest/1036862 to your computer and use it in GitHub Desktop.
Synchronise twinkle's Do-Not-Disturb toggle with whichever status Skype has.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/** | |
* twinklesync.php | |
* Synchronise twinkle's Do-Not-Disturb toggle with whichever status Skype has. | |
* 13-Apr-2011 | |
* | |
* PHP Version 5 | |
* | |
*/ | |
set_time_limit(0); | |
$dbus = new Dbus(Dbus::BUS_SESSION, true); | |
$running = false; | |
$spin = '|/|\\'; | |
$counter = 0; | |
while(!$running) { | |
echo $spin[$counter]; | |
$counter++; | |
if ($counter == 4) { | |
$counter = 0; | |
} | |
try { | |
$proxy = $dbus->createProxy("com.Skype.API", "/com/Skype", "com.Skype.API"); | |
$proxy->Invoke("NAME PHP"); | |
$proxy->Invoke("PROTOCOL 7"); | |
$running = true; | |
} catch(Exception $e) { | |
} | |
sleep(1); | |
echo chr(8); | |
} | |
class Watcher | |
{ | |
static function notify($a) | |
{ | |
global $proxy; | |
static $prevStatus = ''; | |
static $dnd = false; | |
@list($a, $b, $c, $d) = explode(' ', $a, 4); | |
var_dump($a, $b, $c, $d); | |
if ($a === "USERSTATUS") { | |
if ($prevStatus != $b) { | |
switch($b) { | |
case "ONLINE": | |
case "SKYPEME": | |
if ($dnd) { | |
exec("/usr/bin/twinkle --cmd dnd"); | |
} | |
$dnd = false; | |
break; | |
case "AWAY": | |
case "DND": | |
case "INVISIBLE": | |
case "NA": | |
case "OFFLINE": | |
if (!$dnd) { | |
exec("/usr/bin/twinkle --cmd dnd"); | |
} | |
$dnd = true; | |
break; | |
default: | |
echo "Unknown state: $b\n"; | |
} | |
} | |
$prevStatus = $r; | |
} | |
} | |
} | |
$dbus->registerObject('/com/Skype/Client', 'com.Skype.API.Client', 'Watcher'); | |
do { | |
$s = $dbus->waitLoop(100); | |
} while (true); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment