Stupid Mac::Glue/X-Chat Tricks

pudge on 2004-01-21T21:23:46

X-Chat has a perl interpreter plugin that allows you to compile (and cache, like mod_perl) perl scripts.

One of its functions is to open a URL in a wbe browser when you click on it in a window. browser.pl gets the URL and opens it via system('open', $url).

I leave X-Chat Aqua open on my server 24/7. Then I use my laptop, right next to it, to do most other work, including web browsing. I've been using ClipboardSharing to automatically sync my clipboards between the two machines, so I can copy the URL in X-Chat on the server, and then paste it in a browser window on my laptop.

But I decided, why not have clicking on the URL open a browser window on my laptop instead of the local server?

Enter Mac::Glue!

I added this to the top of browser.pl:

use Mac::Glue ':all'; my $browser = new Mac::Glue 'Safari'; my $version = $browser->prop('version');

my @hosts = qw(bourque orr);

sub _gethost { my $found = 0; for my $host (@hosts) { $browser->ADDRESS(eppc => Safari => $host); $found = 1, last if &_alive; } $browser->ADDRESS if !$found; }

sub _alive { return $version->get; }


And then changed the open line:

# system ("open", $url); _gethost(1); $browser->activate; $browser->open_location($url);

Now, if my laptop is on the network (both hostnames are the same machine, one wireless hostname and one wired), it will open the URL on the laptop when I click on it. Otherwise, it opens it locally. Nifty.