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

Re: [MacPerl] Suggestion for a MacPerl Extension



Gaspard Gendreau writes on 15-JUL-1996:

!Andrew McDermott wrote:
!> =
!> > From neeri@iis.ee.ethz.ch Thu Jul 11 17:43 BST 1996
!> > From: Gaspard Gendreau <Gaspard.Gendreau@esrin.esa.it>
!> >
!> > In other words, I would like to do the following:
!> >
!> > - drop some text (or a file) onto the droplet
!> > - this text (or the content of the file, if I drop a file) would be
!> >   the input of my droplet, as if received from an HTTP server
!> > - the output of my script would be sent directly to my Web browser
!> >
!
!> I beleive netscape has "remote control" extensions which would allow you
!> to do this, not only from Macs, but also Windoze and Unix too! (Caveat =
!> different for windows, macs and Unix) I once wrote a perlscript which
!> would read some newsgroups with respect to my .newsrc file and then
!> send an http document to netscape with URLs for the next item in each
!> newsgroup. My next step ws to do this for the Mac, but I was told
!> "this is not the way to do it".

Mosaic too tried to get a "CCI" going - it was to be a "Common Client 
Interface" - a proposed protocol for writing "scripts" that would allow remote 
control of a web-browser (they especially had in mind things like automated 
demos).

!> Check out Netscape's help pages - I'm sure you'll have something writte=
!> in no time.
!
!Thanks. I looked the doc, but found nothing really straightforward to do
!what I am looking for, excepted maybe the shareware Flypaper
!(http://www.pass.wayne.edu/~eric/flypaper/) that calls AppleScripts
!directly from Netscape.

If you want to use perl as a netscape plugin have a look also at the doc at:

  http://www.arc.ab.ca/vr/opengl/plugin.html

(which features a Unix graphics lib - but the idea is sound).

I have here a MacPerl application that I think will do what the original poster 
had requested. The script requires some configuration (most especially 
changeing the $browser string). I cannot fully recommend use of this one as it 
makes use of the old perl4 qw(url_get.pl URL.pl ftplib.pl) libraries
(available for a limited time from:

 http://w4.lns.cornell.edu/~pvhp/perl/mac/lib/

) rather than the sleeker mac-libwww modules. (I cannot seem to retrieve things 
beyond w4 is but one of the troubles I have!)



This is a MacPerl application that allows one to drop a formatted text file 
onto the droplet, it retrieves URLs and saves them to local filenames given in 
the input text file. As it reaches the last URL it runs an AppleScript that 
directs a (configurable) browser to view the local files.

Note that I retrieve the URLs then make them be MacPerl TXT files - I could 
have chosen another application but the editor in MacPerl is good enough for me 
(er, well I do wish it had a built in search - but I can always do that as a 
separate MacPerl script eh?). Note also I did not use the here-document form of 
writing the script. This was just silly superstition on my part from using 
another language (DCL don't ask :-{

Here is a simple example of an input file (saved as TEXT):

!-----------8<------------------------------
http://w4.lns.cornell.edu/      index.html
!----------->8------------------------------

Here then is the script (I called it 'URL get drop') - save as a droplet:

=cut

#!/usr/bin/perl

# welcome to 'URL get drop'
# please drop a text file that contains data in to form:
#
#$url\s+$local_file
#
# for example:
#
#http://w4.lns.cornell.edu/     index.html
#http://w4.lns.cornell.edu/~pvhp/perl/macperl.html  myMac:MacPerl f:web site:macperl.html
#
# OK?

#-----------------------------------------------------------------
# configuration options you will likely want to change to suit
# your Mac:

my $browser = "myMac:Netscape Navigator 2.02 Folder:Netscape Navigator2.02";
my $localhost = 'localhost';
my @file_attributes = ("McPL", "TEXT");
my $quit = 2;

# packages that need to be in your ':MacPerl f:lib:' folder:

require "GUSI.ph";
require "url_get.pl";

#-----------------------------------------------------------------

while (<>) {

    /(\S+)\s+(.*)/;
    my ($url, $local_file) = ($1, $2);

    if ($url) {
#    print "Retreiving $url Please be patient.\n";

        # These two constitute a Unix 2 Mac Hack:
        eval { @urllines = split(/\n/, &url_get($url) ); };
        @html = join("\n",split(/\012/,$urllines[$#urllines]));

        open (FH, ">$local_file") or warn "Error - could not open $local_file $!";
        print FH @html or warn "Error - could not write to $local_file $!";
        close(FH) or warn "Error - could not close $local_file $!";

        &MacPerl::SetFileInfo(@file_attributes, "$local_file");
    }
}

my $local_file_slashed = join('/',split(/\:/,$local_file));

my $script = 
"tell application \"$browser\"\n".
"       GetURL \"file://$localhost/$local_file_slashed\"\n".
"          activate\n".
"end tell\n";

&MacPerl::DoAppleScript($script);
&MacPerl::Quit($quit); 
exit;

__END__

Peter Prymmer
pvhp@lns62.lns.cornell.edu