[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] 35 lines of code



This script downloads today's Dilbert (not the week-delayed one, by faking
an HTTP_REFERER header), then saves it in $ENV{TMPDIR} and sets it as the
desktop picture on my second screen.  Change the value of scrn: to 1 or 0
if you like (o is main).  Very powerful script for 35 lines.  Have fun.

#!perl -w
use LWP::UserAgent;
use Mac::AppleEvents::Simple;
use Mac::Files;
my($ua, $req, $res, $url, @time, $time);

@time = localtime();
$time = substr($time[5], -2, 2) . sprintf('%-.2d%-.2d', ++$time[4], $time[3]);
$url  = "http://umweb1.unitedmedia.com/servers/weblink/stripServer/bin/" .
        "stripsrv01.cgi?Push=dt$time";

$ua   = LWP::UserAgent->new();
$req  = HTTP::Request ->new(GET => $url);

$ua->agent('Mozilla/5.0 (Dev)');
$req->referer($url);

$res = $ua->request($req);

if ($res->is_success()) {
  open(F,">$ENV{TMPDIR}dilbert$time") or die $!;
  print F $res->content();
  close(F);
  do_event(qw/aevt odoc MACS/, "'----':alis(\@\@)",
    NewAliasMinimal(FindFolder(kOnSystemDisk(), kControlPanelFolderType()) .
    ':Desktop Pictures')
  );
  do_event(qw/dskp sdpx dkpx/,
    q"'----':alis(@@), posn:ecen, algn:enon, scrn:2",
    NewAliasMinimal("$ENV{TMPDIR}dilbert$time")
  );
  do_event(qw/aevt quit dkpx/);
} else {
  printf "Error: %s %s\n", $res->code(), $res->message();
}

__END__

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch