Interfacing Acrobat Reader with Google Chrome

This is a small success story about making a small script to interface a stupid program with another that it should be able to talk to in the first place. I tried to configure my Adobe Reader in Linux to use Google Chrome to open ducument URLs, and to my chagrin, when I tried to open a link in a PDF document it opened Chrome with some stupid code in the URL bar. I then decided to make a script that Reader could call that would interpret its commands and then call Chrome appropriately.

With Firefox it works… What Reader does is to call firefox with “-remote openURL(http://example.com,new-tab)”. Lots of stupid bureaucracy, isn’t it? Why all that? It should just call the command with the damn URL as an argument!!!

This is how google-chrome works. If you call chrome with the URL it opens it up the way I want, with the page on a new tab. So all I needed was to strip all the stupid syntax, extract the URL and execute chrome with the URL as an argument.

To me, that’s the perfect work for a bash script with a perl one-liner. Here it is:

#!/bin/bash
google-chrome `echo $2 | perl -wne $'print $1 if m/openURL\((.*),new-tab\)/'`

bash picks up the second argument sent by Reader, to skip the “-remote”, then perl finds the URL inside all the crazy and useless syntax and spits it out. Then bash executes chrome with it.

This is it. Knowing a little bit of bash, perl and regex can bring you some happiness when you are being a victim of a bad program.

Advertisements

One thought on “Interfacing Acrobat Reader with Google Chrome

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s