I received this on the festvox maillist, but thought it was interesting enough to repost here.

#!/usr/bin/perl -w # # load_docs.pl # # Summary: Loads html files into a mozilla instance. # If mozilla is not loaded # then fork an instance first. # # Caveat: This script requires mozilla. # # Message-ID: <4399FFEA.9040406@ispmonsters.com> # Date: Fri, 09 Dec 2005 14:06:34 -0800 # From: "J.A.H." <heblack@ispmonsters.com> # Subject: Script to load docs in mozilla. # # Hello. This script helps set up your programming # environment so that... documentation is automatically # loaded into mozilla. That way less time # is spent getting ready each time. It is my first useful # Perl script. So if you know Perl maybe you could # show me something about Perl. Thanks! use strict; my $pid; my @docs = qw( file:///home/Notes.txt file:///usr/non-portage/fox-1.4.25/share/doc/doc.html file:///usr/non-portage/fox-1.4.25/share/doc/ref/index.html http://www.google.com ); # Look for instance of mozilla. `mozilla -remote "ping()"`; if ( $? ) { # Error, mozilla is not running. if (!defined($pid = fork())) { # Undef branch of fork: die "Cannot fork: $!"; } elsif ($pid == 0) { # Child branch of fork: `mozilla`; # Start new instance.... } else { # Parent branch of fork: do { # Must ensure the child # instance is loaded. Is # there a system way to # wait without relying # on the -remote ping() # feature... Without # waiting there is a # problem executing the # sub to load the # documentation. `mozilla -remote "ping()"`; sleep 1; } while ( $? ); # Bugfix!!? we can -remote "ping()" sleep 1; # but we can not -remote openFile # after that ... unless there is another # sleep here for some reason. load_docs(); $pid=waitpid($pid, 0); # Wait for the pseudo-process containing the # new mozilla instance to end. } } else { load_docs(); } sub load_docs { my $element; foreach (0..$#docs){ if ( $_ == 0 ) { if ( $docs[$_] =~ /~file:\/\// ) { `mozilla -remote "openFile($docs[$_])"` ; } else { `mozilla -remote "openURL($docs[$_])"` ; } } else { if ( $docs[$_] =~ /~file:\/\// ) { `mozilla -remote "openFile($docs[$_], new-tab)"` ; } else { `mozilla -remote "openURL($docs[$_], new-tab)"` ; } } } } __END__


I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re: mozilla-doc loader
by zentara (Cardinal) on Dec 11, 2005 at 17:25 UTC
    I would probably make a change to this script, so it can take files (and/or urls) on the commandline too; and if no @ARGV defaults to "load-defaults". It needs to use Cwd because mozilla needs full pathnames to files.
    #!/usr/bin/perl -w use strict; use Cwd; my $pid; my @docs; if(@ARGV){ my $cwd = getcwd; # @docs = map {'file://'.$_} @ARGV; # dosn't work ... get index file instead # needs cwd foreach my $arg(@ARGV){ if( $arg =~ /^http:\/\/.*$/ ){ push @docs, $arg } else{ push @docs , "file://$cwd/$arg" } } } else{ #load defaults @docs = qw( file:///home/zentara/1down/1GET http://www.google.com ); } # Look for instance of mozilla. `mozilla -remote "ping()"`; if ( $? ) { # Error, mozilla is not running. if (!defined($pid = fork())) { # Undef branch of fork: die "Cannot fork: $!"; } elsif ($pid == 0) { # Child branch of fork: `mozilla`; # Start new instance.... } else { # Parent branch of fork: do { `mozilla -remote "ping()"`; sleep 1; } while ( $? ); # Bugfix!!? we can -remote "ping()" sleep 1; # but we can not -remote openFile # maybe select(undef,undef,undef,.5); # for speedup ... unless there is another # sleep here for some reason. load_docs(); $pid=waitpid($pid, 0); # Wait for the pseudo-process containing the # new mozilla instance to end. } } else { load_docs(); } sub load_docs { my $element; foreach (0..$#docs){ if ( $docs[$_] =~ /~file:\/\// ) {`mozilla -remote "openFile($docs[$_], new-tab)"` ; } else { `mozilla -remote "openURL($docs[$_], new-tab)"` ; } } }

    I'm not really a human, but I play one on earth. flash japh