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
|