exmh with mozilla, firefox, dillo, opera, galeon, ...
Rick Baartman <[email protected]>
| Newsgroups | gmane.mail.exmh.user |
|---|---|
| Message-ID | <[email protected]> |
With apologies to Mark Bergman who now sees his perl code morphed into something he probably did not intend, here is a browser-remote that you can fairly easily customize to submit exmh (or XEmacs) browser requests to any running browser. If you have criticism, please let me know; I know nearly nothing about perl... (off-topic; I use this in XEmacs because often (in cases like a ps or pdf), I want to `browse-url-of-dired-file' instead of actually editing the file.) --rick baartman _______________________________________________ Exmh-users mailing list [email protected] https://www.redhat.com/mailman/listinfo/exmh-users
browser-remote
(text/plain, 4.1 KB)
#! /usr/bin/perl
# Author: Rick Baartman, TRIUMF.
# Script to open supplied URL in the window of the currently-running
# browser. This was hacked from Mark Bergman's code. It is simpler
# but has fewer checks; e.g., it does not care if more than
# one browser running...
# One thing I would like, but don't know how to code is to have an order
# of preference if more than one browser is running.
# It now works for
# both local files and URLs, and works both in exmh (tested in 2.7.2) and in
# XEmacs (tested in 21.4).
# Except for one thing: Unless exec calls of browsers are terminated with &,
# exmh hangs, but XEmacs does not.
# If terminated, exmh works, but XEmacs does not work at all. To get round
# this without using two nearly identical scripts,
# use a wrapper for exmh with the single line:
# browser-remote $1 &
#
# In XEmacs, you need the following somewhere in your startup files:
# (setq browse-url-browser-function (quote browse-url-generic))
# (setq browse-url-generic-program "browser-remote")
# (or just set them using the customization interface)
#
# In exmh, Preferences...WWW..., set your URL viewer to netscape and set
# the netscape command to:
# exmh-browser-remote $xuri
# where exmh-browser-remote is the one-line script mentioned above.
#
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
$running_under_some_shell="/dev/null"; # Shut up the -w option!
$DEBUG=0;
use diagnostics;
use integer;
$|=1; # Flush output
my $url="";
my $BROWSER="";
# my $defaultBROWSER="opera";
# my $defaultBROWSER="galeon";
# my $defaultBROWSER="mozilla";
# my $defaultBROWSER="firefox";
# ...if no browser (besides Dillo) running, the quickest thing to start is Dillo..
my $defaultBROWSER="dillo";
# second choice needed for cases where dillo fails.
my $defaultBROWSER2="galeon";
# Find out what browser is running; add any other tests you like...
open(PS,"ps -e|") or die "Could not get pipe from ps";
FIND: while (<PS>)
{
if ( $_ =~ / opera$/)
{
$BROWSER="opera";
print STDERR "Found $BROWSER in ps output\n";last FIND;
}
elsif ( $_ =~ / firefox$/ )
{
$BROWSER="firefox";
print STDERR "Found $BROWSER in ps output\n";last FIND;
}
elsif ( $_ =~ / mozilla-bin$/ )
{
$BROWSER="mozilla";
print STDERR "Found $BROWSER in ps output\n";last FIND;
}
elsif ( $_ =~ / galeon-bin$/)
{
$BROWSER="galeon";
print STDERR "Found $BROWSER in ps output\n";last FIND;
}
}
close(PS) or die "Could not close pipe from ps";
if (defined($ARGV[0]) )
{
$url = $ARGV[0];
}
else
{
print STDERR "No URL given.\n";
exit 1;
}
# Only firefox and mozilla appear to be ping-able. I use this to avoid popping
# up the URL on the wrong display (I use vnc, so have more than one running).
# If any other browser is running on a display different from the one in which
# the browser-remote is run, it will silently display on the wrong display.
# I don't know any workaround...
$PING{firefox}="$BROWSER -remote \"ping()\" 1> /dev/null 2>&1";
$PING{mozilla}="$BROWSER -remote \"ping()\" 1> /dev/null 2>&1";
if ($BROWSER eq "firefox" || $BROWSER eq "mozilla") {
`$PING{$BROWSER}`;
if ($? != 0 ) {
print STDERR "Apparently, no $BROWSER running on THIS X-Display.\n";
$BROWSER="";
}}
if ($BROWSER eq "")
# This opens the default browser.
{
$BROWSER=$defaultBROWSER;
print STDERR "Could not find running browser, using default: $BROWSER\n";
if (($url =~ "^https://") && ($BROWSER =~ "dillo")){
print STDERR "Oops: Dillo can't do https; using second choice.\n";
$BROWSER=$defaultBROWSER2}
exec "$BROWSER $url";
}
else
# This opens in a new tab in the browser that's running. If more than one is running,
# you'll have to look for it.
#
# Add any other browser according to its syntax for tabs.
{
if ($BROWSER eq "firefox") {
exec "firefox -remote 'openURL($url,new-tab)'"}
elsif ($BROWSER eq "mozilla") {
exec "mozilla -remote 'openURL($url,new-tab)'"}
elsif ($BROWSER eq "opera") {
exec "opera -nosession -remote 'openURL($url,new-page)'"}
elsif ($BROWSER eq "galeon") {
exec "galeon -n $url"};
}
exit 0;