3

Working on a script to automate some tasks in Firefox.

These tasks should run through a clean Firefox profile, so they are fast and don't interfere with any of my regular surfing.

#!/bin/bash

# Launch clean firefox profile with parameters:
# -no-remote    don't connect to any running instance of firefox
# -P        run firefox through a profile
firefox -P 'Another Profile' &
sleep 4 # wait for firefox to load

# Open URLs
firefox -new-tab 'http://askubuntu.com/users'
firefox -new-tab 'http://askubuntu.com/badges'

Unfortunately, I can't get the URLs to open in the profile "Another Profile". Instead, Ubuntu launches Firefox with my default user profile and opens them, there.

Any suggestions on how to open them in "Another Profile"?

André Marinho
  • 910
  • 9
  • 23
somethis
  • 894
  • 3
  • 12
  • 30

2 Answers2

2

If you omit the profile, firefox will open the URL in one of your open Firefox programs. You have to explicitly mention it:

firefox -P 'Another Profile' http://example.com/

You can also open multiple URLs at once and combine it, removing the need for a sleep:

firefox -P 'Another Profile' http://example.com/ http://example.net/
Lekensteyn
  • 171,743
  • 65
  • 311
  • 401
  • Thanks, works like a charm! Can't believe I tried for so long and this didn't occur to me. – somethis May 05 '13 at 13:14
  • Instead of opening Firefox, you may also want to consider using `curl` with a cookie jar (or the `-b cookieName=cookieValue` arguments). See the manual page of `curl` for more details. – Lekensteyn May 05 '13 at 13:16
  • Just noticed that the above solution doesn't work if firefox is already open with my default profile. Normally firefox -P **-no-remote** 'Another Profile' http://example.com/ would do the trick. But then it's not possible to open the URLs anymore. – somethis May 05 '13 at 14:12
  • Thank you for pointing out curl, too. It's a complex scrape which I'm running through iMacros, though. 20+ different sites with ajax code etc. :) – somethis May 05 '13 at 14:14
  • I see, I usually run with `-no-remote` and then close the window after I am done so I did not encounter the issue. Perhaps the Mozilla documentation can help you further, `firefox -help` did not show any useful for this case. – Lekensteyn May 05 '13 at 14:18
  • ok, nah, I read through the documentation. Thanks! – somethis May 05 '13 at 20:48
1

One thing I've done to get around the issue you mentioned is open a local html file with a simple javascript redirect. I open firefox in the profile and give that local html page as the url.

Here is an example of the code I use in the html file to redirect to my macro. I'm sure there are better ways, but this works well enough for me for now. Oh, I also use the close all others tag to clear the initial page.

<script language="JavaScript">
function redirect() {
    window.location.href = 'http://run.imacros.net/?m=Macro_folder/sub_folder/macro.js';
}
setTimeout(function(){
    redirect();
},(5 * 1000));
</script>
Aten
  • 11
  • 1