Skype convergence

Last week I wrote:

Next stop is, ideally, to get Skype to automatically update Last Contacted as well, which is perhaps a little bit of a pipe dream.

But then I thought "Skype has an API. I have Mac::Glue. This should be easy!" And it is. Harder than it needs to be, but still easy.

use Mac::Glue qw(:all);
use Time::Piece;
my $s = Mac::Glue->new("Skype");
my $ab = Mac::Glue->new("Address Book");
sub skype { $s->send(command => shift, script_name => "LastContacted") }

my %skypers; # Map of skype user (stored as a "skype:whatever" tag in the
             # contact's "note") to email address
for ($ab->prop("people")->get) {
    next unless $_->prop("note")->get =~ /skype:(\S+)/;
    my $mail = $_->prop("email")->get;
    $mail &&= $mail->prop("value")->get and $skypers{$1} = $mail;
}
my $c = skype("SEARCH RECENTCHATS");
$c =~ s/CHATS //; my @chats = split /, /, $c;
my $today = Time::Piece->new->ymd;
for (@chats) {
    my $ts = skype("GET CHAT $_ TIMESTAMP"); $ts =~ s/.*TIMESTAMP //;
    # We can't set it to a given date, sadly, so just pick out today's chats
    next unless Time::Piece->new($ts)->ymd eq Time::Piece->new->ymd;
    my $members = skype("GET CHAT $_ MEMBERS");
    $members =~ s/.*MEMBERS //;
    for (grep {!/lathosjp/} split / /, $members) { # Not me!
        if (!$skypers{$_}) { warn "Couldn't find email address for $_"; next }
        # Mac::Glue treats values of the contact_info class as
        # read-only, need to shell out to Applescript to get it done...
        system("osascript", "/Users/simon/update-last-sent.osa", $skypers{$_});
    }
}

Run this from cron, and Robert is your father's brother!


Full version - 3 Comments