October 31, 2007 Archives

Wed Oct 31 11:11:08 CDT 2007

Remotely load a URL in Firefox

Today's trick is to write a script that will start a new Firefox tab with a page that you specify. Maybe you want to schedule a page to load with cron to check your todo list in the morning. Maybe you have found a page that your wife is looking for, and easier than signing into a chat service is to ssh to her computer and load the page for her. Or, maybe you want load a webpage so that you can take a screenshot of it from a remote location.

The code for this is very similar to the screenshot code. You must set some ENV variables so that X knows where to find your Firefox. Also, this version only seems to work if you already have Firefox running. I expect that removing the 'new-tab' option will fix that, but then you get a new window.

This is the code:
#!/bin/bash
#Script to load a url in a new Firefox tab.  Works remotely.
webpage="http://www.google.com/"
if [ $# = 1 ]; then
        webpage="$1"
fi
DISPLAY=:0
export DISPLAY
HOME=/home/nesman
export HOME

firefox --remote "openurl($webpage ,new-tab)"
The first few lines check to see if you have given a page to load. If not, it will default to Google.

Posted by Nesman | Permanent Link