Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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.

#!/usr/bin/perl

use strict;

use constant USAGE => <<EOU;
USAGE:
$0 (filename|URL|mailto:email\@addre.ss)
EOU

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

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

system "mozilla", "-remote", sprintf($command, $_);
Comment on mozilla -remote made simple
Download Code
Re: mozilla -remote made simple
by Helter (Chaplain) on Oct 10, 2002 at 13:00 UTC
    I've been waiting for this feature.....here 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

    Sweet!

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

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 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 30, 2002 at 16:48 UTC

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

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\@bar.com)\n"; exec 'mozilla', -remote => sprintf($command, $_);
    This checks -r early - thus, you can use it to invoke Mozilla on a directory called www.foo.bar/ 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

        --
        b10m

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-07-28 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (187 votes), past polls