« Dawn... | Main | One of those days... »

August 10, 2005

search cpan and open Safari from perl

#!/usr/local/bin/perl
use warnings;
use strict;
use WWW::Mechanize;
use Mac::AppleScript qw(RunAppleScript);

my $search = shift || "WWW::Mechanize";

my $mech = WWW::Mechanize->new();
$mech->get("http://search.cpan.org/");
$mech->form(1); #use the first form
$mech->field("query",$search);
$mech->click;

my $link = $mech->find_link(text => $search)->url_abs();

my $script =<<END;
set searchURL to "$link"
tell application "Safari"
    open location searchURL
end tell
END

RunAppleScript($script)
    or die "Didn't work!";

exit(0);

Posted by ed at August 10, 2005 2:52 PM

Trackback Pings

TrackBack URL for this entry:
http://weblogs.litmusgreen.com/mt-tb.cgi/684

Comments

Post a comment




Type the characters you see in the picture above.


Remember Me?