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

[MacPerl] fun with Anarchie Pro 3.5 / Netscape



Spurred by a request from Vicki Brown for something similar, I came up with
this today.

It will take the URL of the frontmost Netscape window and open that file in
BBEdit for editing with Anarchie Pro.  Any recent version of BBEdit and
Anarchie Pro 3.0 or higher should work.  I don't know what version of
Netscape is required, but 4.5.1 works.

Not very complicated code at all.  Have fun.

--Chris


#!perl -w

=pod

=head1 NAME

edit_url


=head1 SYNOPSIS

Edit URL of frontmost Netscape window in BBEdit via Anarchie Pro.

Tested with Netscape Communicator 4.5.1, Anarchie Pro 3.5, BBEdit 5.0.


=head1 DESCRIPTION

Set up accounts in your "$ENV{HOME}netrc" file, if you trust it
I have my $ENV{HOME} set to my prefs folder, so that's where I put
the netrc file.  Check L<Net::Netrc> for more info.

If you don't want to use Net::Netrc, you can change this:

      ($user, $pass) = get_info($url);

to something like:

      ($user, $pass) = ('me', 'pass');

or even skip them altogether.  If no password is present, Anarchie
Pro will prompt for it.  if no username is present, MacPerl will
prompt for it.  If none is given in the prompt, anonymous will be
assumed.

You will need to adjust the regexes in the "edit this part for your
sites" section to suit your needs.

=head1 AUTHOR

Chris Nandor E<lt>pudge@pobox.comE<gt>, http://pudge.net/

Copyright (c) 1999 Chris Nandor.  All rights reserved.  This program is
free software; you can redistribute it and/or modify it under the terms
of the Artistic License, distributed with Perl.

Thanks for the idea from Vicki Brown.


=head1 VERSION

19990323

=cut

use Mac::AppleEvents::Simple 0.60;      # for get() method
use Net::Netrc 2.08;                    # make sure it works with Mac OS
use URI;
use strict;
my($user, $pass, $id, $url);

$Mac::AppleEvents::Simple::SWITCH = 0;  # don't bring Netscape to the front

$id  = do_event(qw{WWW! LSTW MOSS})->get;
$url = do_event(qw{WWW! WNFO MOSS}, "'----':$id")->get;

#### edit this part for your sites ####

if ($url =~ m|^https?://\w+.petersons.com/f?cgi-bin/|) {
    $url =~ s|^https?://(\w+.petersons.com)/(.*)$
             |ftp://$1//web/ns-home/$2|x;
} elsif ($url =~ m|^https?://\w+.petersons.com/|) {
    $url =~ s|^https?://(\w+.petersons.com)/(.*)$
             |ftp://$1//web/ns-home/doc/$2|x;
} elsif ($url =~ m|^https?://pudge.net/|) {
    $url =~ s|^https?|ftp|;
} else {
    MacPerl::Answer('Cannot edit URL, it is not recognized.');
    exit;
}

($user, $pass) = get_info($url);

$url =~ s|/$|/index.html|;  # get index.html if ends in /

#### ############################# ####

$user = $user
    || MacPerl::Ask('User name? (leave blank for anonymous)')
    || 'anonymous';

$Mac::AppleEvents::Simple::SWITCH = 1;  # bring Anarchie to front

if ($pass) {
    do_event(qw{Arch BBEd Arch}, q{ArUR:TEXT(@), ArGU:TEXT(@), ArGp:TEXT(@)},
        $url, $user, $pass);
} else {
    # Anarchie will prompt for password
    do_event(qw{Arch BBEd Arch}, q{ArUR:TEXT(@), ArGU:TEXT(@)},
        $url, $user);
}

sub get_info {
    my $url = shift or return;
    return (Net::Netrc->lookup( URI->new($url)->host )->lpa)[0,1];
}

__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 macperl-request@macperl.org