cd /D
"%APPDATA%\Mozilla\Firefox\Profiles"
cd *.default set ffile=%cd% echo
user_pref("network.proxy.http",
"%1");>>"%ffile%\prefs.js" echo
user_pref("network.proxy.http_port",
3128);>>"%ffile%\prefs.js" echo
user_pref("network.proxy.type",
1);>>"%ffile%\prefs.js" set ffile= cd
%windir%
This is nice ! Thanks for writing this. I needed this exact piece of code for Windows. My goal was to do this by learning to do it with Linux first and then learn the Windows shell which I was not happy about having to do so you saved me some time!
My Linux version is at the bottom of this post. I've been experimenting with which file to insert the prefs into. It seems picky. First I tried in ~/.mozilla/firefox/*.default/prefs.js but it didn't load very well. The about:config screen never showed my changes. Currently I've been trying to edit the actual Firefox defaults file. If someone has the knowledge off the top of their head could they rewrite the Windows code to only add the lines if they're not already in there? I have no idead how to do sed/awk stuff in Windows without installing Cygwin first.
The only change I was able to make to the Windows scripts is above in the quoted part. I change the IP to %1 so when you call the script from the command line you can give it an option instead of having to change the file.
#!/bin/bash
version="`firefox -v | awk '{print substr($3,1,3)}'`"
echo $version " is the version."
# Insert an ip into firefox for the proxy if there isn't one
if
! grep network.proxy.http /etc/firefox-$version/pref/firefox.js
then echo 'pref("network.proxy.http", "'"$1"'")";' >> /etc/firefox-$version/pref/firefox.js
fi
# Even if there is change it to what we want
sed -i s/^.*network.proxy.http\".*$/'pref("network.proxy.http", "'"$1"')";'/ /etc/firefox-$version/pref/firefox.js
# Set the port
if ! grep network.proxy.http_port /etc/firefox-$version/pref/firefox.js
then echo 'pref("network.proxy.http_port", 9980);' >> /etc/firefox-$version/pref/firefox.js
else sed -i s/^.*network.proxy.http_port.*$/'pref("network.proxy.http_port", 9980);'/ /etc/firefox-$version/pref/firefox.js
fi
# Turn on the proxy
if ! grep network.proxy.type /etc/firefox-$version/pref/firefox.js
then echo 'pref("network.proxy.type", 1);' >> /etc/firefox-$version/pref/firefox.js
else sed -i s/^.*network.proxy.type.*$/'pref("network.proxy.type", 1)";'/ /etc/firefox-$version/pref/firefox.js
fi
The easiest way to do this is to configure your Firefox to use a PAC with a file URL, and then change the file URL from the line command before you start Firefox.
This is the easiest way. You don't have to write a script that remembers what path to prefs.js is (which might change over time).
You configure your profile once, and then you edit the external file whenever you want.
I needed to set an additional option to allow SSO passthrough to our intranet site. I added some code to an example above.
You could also use this Powershell script I wrote to do just this, and all other Firefox settings as well.
https://bitbucket.org/remyservices/powershell-firefoxpref/wiki/Home
Using this you could easily manage Firefox using computer startup and user logon scripts. See the wiki page for directions on how to use it.
Firefox? I don't think you can. IE is another story though..
This is nice ! Thanks for writing this. I needed this exact piece of code for Windows. My goal was to do this by learning to do it with Linux first and then learn the Windows shell which I was not happy about having to do so you saved me some time!
My Linux version is at the bottom of this post. I've been experimenting with which file to insert the prefs into. It seems picky. First I tried in ~/.mozilla/firefox/*.default/prefs.js but it didn't load very well. The about:config screen never showed my changes. Currently I've been trying to edit the actual Firefox defaults file. If someone has the knowledge off the top of their head could they rewrite the Windows code to only add the lines if they're not already in there? I have no idead how to do sed/awk stuff in Windows without installing Cygwin first.
The only change I was able to make to the Windows scripts is above in the quoted part. I change the IP to %1 so when you call the script from the command line you can give it an option instead of having to change the file.
You can easily launch Firefox from the command line with a proxy server using the -proxy-server option.
This works on Mac, Windows and Linux.
path_to_firefox/firefox.exe -proxy-server %proxy_URL%
Mac Example:
/Applications/Firefox.app/Contents/MacOS/firefox -proxy-server proxy.example.com
The easiest way to do this is to configure your Firefox to use a PAC with a file URL, and then change the file URL from the line command before you start Firefox.
This is the easiest way. You don't have to write a script that remembers what path to prefs.js is (which might change over time).
You configure your profile once, and then you edit the external file whenever you want.