Sunday, September 13, 2009

Suspend/Hibernate from command line

On a *NIX system, there are two main message buses: a system-wide one and one for each user session. The "dbus-send" command can send messages to either of the buses with --system or --session options along with a variety of options. Long story short, if you want to suspend or hibernate your machine, you need to send messages to org.gnome.PowerManager, not sure how it is for KDE systems. This is what your respective GUI options do internally.

To suspend, say:

$ dbus-send --session --dest=org.gnome.PowerManager --type=method_call --print-reply --reply-timeout=2000 /org/gnome/PowerManager org.gnome.PowerManager.Suspend

To hibernate, say:

$ dbus-send --session --dest=org.gnome.PowerManager --type=method_call --print-reply --reply-timeout=2000 /org/gnome/PowerManager org.gnome.PowerManager.Hibernate

Thursday, September 10, 2009

Changing HTML class attributes using Javascript

If you try to change the HTML class of an object on the fly using javascript, you might find that it works on Firefox but doesn't work with Internet Explorer. In that case, you're probably doing this:
document.getElementById("myObject").class = "newclass";
However, after being ready to bang my head on the desk for two days and doing a binary search on 500+ subversion revisions to find the exact working/non-working combo for IE, I have discovered this. You ought to use
document.getElementById("myObject").className = "newclass";
Heh... the joys of life.