Skip to content

Instantly share code, notes, and snippets.

@kenguest
Created June 20, 2011 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenguest/1036862 to your computer and use it in GitHub Desktop.
Save kenguest/1036862 to your computer and use it in GitHub Desktop.
Synchronise twinkle's Do-Not-Disturb toggle with whichever status Skype has.
#!/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