Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

mozilla -remote made simple

by giulienk (Curate)
on Oct 10, 2002 at 10:43 UTC ( #204134=snippet: print w/ replies, xml ) Need Help??

Description: I find really interesting the capability of mozilla to open new URLs in new tabs of a already running mozilla process. Still i find the syntax of the command awkward and not really usable. So I added the following snippet to my PATH. It's really simple, but makes the trick.

NB: tested with Mozilla 1.1. It should work even with Mozilla 1.0 but i'm pretty sure it won't work for previous versions.


use strict;

use constant USAGE => <<EOU;
$0 (filename|URL|mailto:email\

$_ = shift;
my $command = 'openURL(%s, new-tab)';

    m!^(ftp|http|file)://! and last;
    s!^mailto:!! and do {
        $command = 'mailto(%s)';
    -r and do {
        require Cwd;
        $_ = 'file://' . Cwd::abs_path( $_ );
    print USAGE and exit;

system "mozilla", "-remote", sprintf($command, $_);
Comment on mozilla -remote made simple
Download Code
Replies are listed 'Best First'.
Re: mozilla -remote made simple
by Helter (Chaplain) on Oct 10, 2002 at 13:00 UTC
    I've been waiting for this at work we have Mozilla 1.0 i686 Linux, and new-tab is not understood. I'm downloading a local copy of 1.2....hopefully it will make all my dreams come true :)
Re: mozilla -remote made simple
by mirod (Canon) on Oct 10, 2002 at 13:51 UTC


    It works with phoenix too (provided you replace mozilla by phoenix of course!)

Re: mozilla -remote made simple
by Aristotle (Chancellor) on Dec 24, 2002 at 16:38 UTC
    A bit tidier and more reliable:
    #!/usr/bin/perl -w use strict; use constant URL => 'openURL(%s, new-tab)'; use constant MAIL => 'mailto(%s)'; sub abs_path { require File::Spec; File::Spec->rel2abs(shift); } $_ = shift || ''; my $command = m!^(?:ftp|http|file)://! ? sprintf URL, $_ : -r($_) ? sprintf URL, 'file://'.abs_path($_) : s!^(www\..+)!http://$1! ? sprintf URL, $_ : s!^(ftp\..+)!ftp://$1! ? sprintf URL, $_ : s/^mailto:// ? sprintf MAIL, $_ : die "usage: $0 (filename|URL|mailto:foo\\n"; exec 'mozilla', -remote => sprintf($command, $_);
    This checks -r early - thus, you can use it to invoke Mozilla on a directory called without the scheme guessing getting in your way. It also handles URLs with ftp.* hosts nicely.

    Makeshifts last the longest.

      Do you know how to start Mozilla mail with the message text already filled in?

        Dunno if this works with all/more browsers, but it does seem to work with Firebird (and I hope this is what you're looking for):

        <a href="mailto:foo@bar.invalid?subject=Testing&body=Oh wow, body text +">foo@bar.invalid</a>

        This works for me, using Firebird and MozEX to launch Pine for me.

        Test it here :) foo@bar.invalid

Re: mozilla -remote made simple
by Aristotle (Chancellor) on Oct 10, 2002 at 18:34 UTC
    Very minor personal pet peeve :-) : print(USAGE), exit;
    You don't actually want to depend on print's return value there - using and works but is more of an accidental feature. ++ though!

    Makeshifts last the longest.

Re: mozilla -remote made simple
by Mr. Muskrat (Abbot) on Oct 10, 2002 at 14:02 UTC

    This does not yet work with Phoenix.

    Update: At least not on win98.

Re: mozilla -remote made simple
by Mr. Muskrat (Abbot) on Oct 30, 2002 at 16:48 UTC

    I upgraded to Phoenix 0.4 this morning and now this works even on Windows 98.

Back to Snippets Section

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://204134]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2015-11-26 23:28 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (709 votes), past polls