Programatically modify firefox settings

I refuse to believe that nobody has needed to silently push firefox setting / configuration in an unattended manner, but I was unable to find any directions on how to do so. In particular, I need to automatically, using a script, modify the no-proxy exclusion list.

Here is the way I eventually ended up doing it.

Firefox stores it’s configuration in prefs.js in the Profile folder for the user.
That is (on XP anyway) C:\Documents and Settings\[user]\Application Data\Mozilla\Firefox\Profiles\[randomtext].default\prefs.js
Which can be specified as %APPDATA%\Mozilla\Firefox\Profiles\[randomtext].default\prefs.js

Since it contains a random string, how the heck do you find it??
Well, you can parse the profiles.ini file in %APPDATA\Mozilla\Firefox. It looks like this:

[General]
StartWithLastProfile=1

[Profile0]
Name=default
IsRelative=1
Path=Profiles/cutfy0h4.default

Luckily, you can use a FOR loop within a winxp/2k batch file to grab the profile name(s).

FOR /F "delims==/ tokens=3 usebackq" %%i IN ("%APPDATA%\Mozilla\Firefox\profiles.ini") DO (
 echo %%i
)

This will echo just the “cutfy0h4.default”, and it will only return for lines of the file that contain 3 fields.
(For more information about the FOR loop, see here: http://www.robvanderwoude.com/ntfor.html.)

Now that we can locate the profile, how the heck do we modify the setting?

Turns out, firefox looks for a file called user.js, and applies those settings AFTER applying prefs.js. Any settings in user.js will be applied to prefs.js.
So you put your settings in user.js, copy it into the profile folder, start and stop firefox, then delete user.js. (If you don’t delete user.js, the user will be unable to modify the setting).

Warnings:
1. I am not responsible if this breaks anything. USE AT YOUR OWN RISK!!
2. If there are multiple profiles, it will not work right. In most cases there should only be one.
3. If firefox adds more stuff to profiles.ini, or fixes the direction of the slash in the profile path, this script will break.
4. This was developed with Firefox 2.0.0.13

Here is my final script:

You will need a file called “user.js.install” in the same folder as the batch file containing whatever settings you want to change. (Use prefs.js as your guide) Like this one:

user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, superserver, 192.168.0.1");

Here is the batch script:

taskkill /IM firefox.exe > javainst.log 2>&1
FOR /F "delims==/ tokens=3 usebackq" %%i IN ("%APPDATA%\Mozilla\Firefox\profiles.ini") DO (
  echo "%APPDATA%\Mozilla\Firefox\Profiles\%%i\prefs.js"  >> proclog.log 2>&1
  IF EXIST "%APPDATA%\Mozilla\Firefox\Profiles\%%i\prefs.js" (
    copy /Y user.js.install "%APPDATA%\Mozilla\Firefox\Profiles\%%i\user.js"  >> proclog.log 2>&1
    start firefox.exe
    rem wait 7 seconds for firefox to start
    ping 1.1.1.1 -n 1 -w 7000
    taskkill /IM firefox.exe  >> proclog.log 2>&1
    del "%APPDATA%\Mozilla\Firefox\Profiles\%%i\user.js"  >> proclog.log 2>&1
  )
)

Javascript gripe # 2

The add() function of the html select object functions totally different in IE and Firefox.

It is defined as :
selectObject.add(option,before)

Where option is an option object. Before is the tricky part.

In firefox, the second parameter is supposed to be a reference to the option object you want to place your new object in front of. In IE, it is the index to the object you want to remove.

These are fundamentally different.

In FF, you have to do this:
boxRef.add(newOpt,boxRef.options[i]);

in IE, you do this:
boxRef.add(newOpt,i);

Apparently, Firefox is correct according to the DOM specifications:
void add(in HTMLElement element, in HTMLElement before) raises(DOMException);
void remove(in long index);

But tell me, why does the add method use an object while the remove uses an index???. The standard is messed up, not IE.

Anyway…

Javascript tip

I was having the most unusual problem in a function that used a for loop to find selected items in a html select list. My iterator variable “i” was for some reasen ending up with a value higher than the for loop would allow.

As it turns out, if you declare a variable without using the “var” keyword, that variable has global scope.

Case in point:

function pressRemove() {
  fromBox = selBox;
  toBox = allBox;
  for (i=fromBox.length-1;i>=0;i--) {
    if (fromBox.options[i].selected) {
	  addOpt(toBox,fromBox.options[i].value,fromBox.options[i].text,2);
	  fromBox.remove(i);
	}
  }
}

The function addOpt includes it’s own for loop, also using a variable named i. That inner for loop was overwriting the value in this for loop!

...
  for (var i=fromBox.length-1;i>=0;i--) {
...

By changing all the for loops to declare their variables, the problem was solved. Personally, I think that is a really stupid “feature”, but since both IE and Firefox do it, it is expected.

Mac vs PC?

Apple is right, 100%. OS X is better than windows hands down. Expecially better than Vista.

Mac computers, on the other hand, are far inferior in value, performance, features, expandability and future-proof-ness.

All of the consumer Mac machines are either one-piece or extremely compact. Can you upgrade? No, Apple makes more money if you buy another EXTREMELY overpriced computer if your old one get too slow.

Every one of Apple’s computers were designed with form overshadowing function. They are pretty, and stylish, but they lack the things that really matter.

If OS X was available on hardware that I could control, upgrade and modify at will, (e.g. a PC) I would switch immediately. Apple could destroy Windows by doing this, and at this point it would be trivial for them to do so (research the Hackintosh…). They will not, though. Apple is well aware that their lucrative hardware sales are driven by the superior operating system, and that nobody in their right mind would pay $2,000 for a Mac when they could get the same thing for $750 in a PC.

I want to create something!

Sometimes I get it the mood to make something beautiful.

Like right now. I want to make music. Composing it would be fine, or performing. But guess what? I cannot do either.

I can hear something, and tell that it is beautiful. I am very good at analyzing music… but I just can’t create it! Nor can I play it very well. My sister has amazing piano skill she takes for granted. A song I struggled with off and on for a month to get one hand at a time slowly… she could sight read both hand at near full speed.
With practice I can get better at a song, but not at playing. When I mess up, I cannot gracefully recover.

It is similar with visual art. I wish I could express the imagery in my mind on paper (or some other format) but my hands are incapable. I can only draw well when I trace, and even then it looks like the work of a child.

I am left-handed. Doesn’t that mean I’m supposed to be more creative?

I often argue that my art is in writing code. I express my creativity through programming. But this is something very few people can appreciate – most would rather not even try.
Occasionally I can be creative with words, but I tend not to write about beautiful things.

It is a stange feeling, the desire to create. It is even more strange to be unable to.

Revenge of the spam-bot

I guess the spammers saw my totally useless complaint about spam, because somehow they managed to defeat the capcha for comment posting.

I’m guessing there was a nucleus exploit, so I have upgraded to the latest version and will see what happens.

Confederate flag = State's rights?

The argument I have heard from “open-minded” individuals is that the use of the confederate flag, or an appreciation / loyalty to the Confederacy is not so much about slavery as it is about state’s rights.

I hereby proclaim this bullcrap.

http://en.wikipedia.org/wiki/Cornerstone_Speech
The Cornerstone Speech is so named because of one section.
In particular,


The new constitution has put at rest, forever, all the agitating questions relating to our peculiar institution — African slavery as it exists amongst us — the proper status of the negro in our form of civilization. This was the immediate cause of the late rupture and present revolution. Jefferson in his forecast, had anticipated this, as the “rock upon which the old Union would split.” He was right. What was conjecture with him, is now a realized fact. But whether he fully comprehended the great truth upon which that rock stood and stands, may be doubted.

(Jefferson’s) ideas, however, were fundamentally wrong. They rested upon the assumption of the equality of races. This was an error. … Our new government is founded upon exactly the opposite idea; its foundations are laid, its corner–stone rests, upon the great truth that the negro is not equal to the white man; that slavery — subordination to the superior race — is his natural and normal condition.

I’m afraid this leaves no room for discussion. The confederacy wasn’t about state’s right; it was about slavery. The confederacy was formed because Republicans – the anti-slavery party – had gained power, and the south didn’t want to lose their cheap labor.

Rationalizing the use of the confederate flag, and glorifying the confederacy is much like doing the same for the swastika, and the nazi party.
Indeed both movements were based on the belief that one race is somehow superior to another.

The difference:
Germany has the common decency to be ashamed of what it did.
The Southern U.S. still doesn’t see what it did wrong.

Hate Spam?

I know I do. Not the meat product – I’m man enough to admit liking it – the emails.

What I find fascinating about them is that I can usually tell in under 1 second whether an email is spam or not from the subject alone. Even on those rare emails that slip through gmail’s filters. Granted, not all people have such a finely tuned spam-o-meter, but it still amazes me that spam continues to be difficult to block. It is so easy for me to tell, yet so hard for a computer. There must be a way to represent the problem is a way that is easier for a computer to comprehend… but I’m not going to waste time pondering that.

Even if we block it, spammers will still send it because it is essentially free, and guaranteed to make it as far as your mail server, and at least into your spam folder where you MIGHT look at it.

The way to significantly reduce spam is to put the filtering software at the other end. Spammers send out large numbers of emails from the same IP address (or small range of IP addresses). When these emails first hit the network, there could be “filtering” software watching for abusive emailing. My support of such a solution depends on how email works – which I am unclear about. If email works like http – where I can set up a server and the ISP does nothing beyond routing packets – then it would be bad to allow ISPs to start snooping. But if sending emails requires the use of an ISP – or somebody’s email server, then the ISP is already involved, and such a filter would be a small imposition. Done right, it could cut spam off at the source, before the complaints start rolling in.

Of course, if everybody used gmail, spammers might realize they are wasting their time.

Open Source

I have long been fond of Open Source solutions, often choosing Open Source over other commercial alternatives for my own use. One reason for this is purely financial: I simply cannot afford a personal copy of photoshop or windows server. So I use The Gimp and Linux.

Now that I am searching for a solution in a corporate environment, needs change. The company will pay for whatever solution I choose.

In particular, I am looking for a future-proof replacement for a bunch of Oracle Forms and Reports. I was initially considering following Oracle’s recommended migration path – switching to Oracle Application Server using Oracle’s java Application Development Framework.
Until I saw the licensing and support costs…

For what we need, the cost is outrageous. The fact that we have to pay a full licensing cost for the dev and production environments is unreasonable.

So I have started looking into other free or Open Source alternatives. JBoss and Geronimo are the two main Open source app servers, but there is no clear winner, nor any decent comparisons other than pseudo-religious GPL vs Apache licensing debates. I need something that will be easy to manage and diagnose. As a relative Java newbie, ease of use is the most important feature.

If I choose a commercial solution, I will undoubtedly get some kind of support from the manufacturer. After having worked with Oracle’s Global support services for two years, I can confidently declare that it is not worth $8,800 / CPU / year (and that is just the database).

But if I choose an open-source solution, I am on my own if something breaks… sort-of.

Oracle’s database is robust and feature-packed, but not if you don’t have access to Metalink (Oracle’s paid support site). Following the publicly available documentation will often run you into bugs. For example, if you try to install Grid Control on a SuSE machine, it will invariably fail if you have any environment variables with spaces, semicolons, percents or other strange characters. This information is only available through Metalink.

Searching the internet will usually not get you any better info about Oracle, because all the support info is hidden in a very expensive support site.

In the case of Open Source software – such as MySQL – all that support information is on the internet. MySQL has a paid support site, but it is generally less useful than newsgroups or forums.

My point is that with commercial software, there isn’t much support on the internet because not as many people use it, and those that do only deal with the software vendor for support. Additionally, the software vendor may consider support proprietary information, and not allow it on the internet. The only option is to pay for support.

With Open Source software, most people look to the internet for support, therefore making most solutions available to the public free of charge.

I still have not made up my mind, but I believe that ultimately free software will provide a significant cost savings.

Words?

When you speak, your words are in my head.
Not a stream of random consonants and vowels.
Not a hierarchy of nouns and verbs.
Not a set of sentences, nor a block of text.

That my ears hear the sound is of small significance;
For me to understand you, I must speak in unison
 - for a moment, despite all else, we think alike -

              Your words, inside my head.