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
  • 974

3 Answers3

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
  • 178,446
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
0

Based on an answer from Att Righ here I developed the following solution which automatically selects the right profile based on the URL.

This wrapper script is tested on Ubuntu Linux 20.04.6 with Mozilla Firefox 104.0.

#!/bin/bash

if [[ "$@" =~ ."google."|"facebook.com"|"instagram.com". ]] then profile=for_evil_sites else profile=default fi

if pgrep --full "firefox\b.*$profile" > /dev/null; then /usr/bin/firefox -P "$profile" "$@" > /dev/null else /usr/bin/firefox --new-instance -P "$profile" "$@" > /dev/null disown $! fi

Save the script with the name firefox e.g. in $HOME/bin/ and make sure it will be loaded instead of your standard firefox. (The directory has to be before the original one in variable $PATH.)