Wednesday, 31 December 2008

Gnome wallpaper switching

Having gathered a few wallpapers I went looking for a wallpaper switcher that would change my Gnome wallpaper automatically on a regular basis.

I found a couple of scripts that would work off a folder (such as Gnome Wallpaper Changer), but I wanted a script/app that used the Gnome wallpaper manager. No point managing wallpaper in two separate places, and when pulling them out of a folder, Gnome doesn't know whether they should be stretched, tiled, centred, etc, etc.

To meet my needs, I threw together the following script:
#!/usr/bin/php
define(DELAY,30 * 60);//Delay between backgrounds, in seconds
define(GNOME_BACKGROUND_FILE,'/home/nick/.gnome2/backgrounds.xml');//XML file containing backgrounds, as per gnome

function getBackgrounds($file = GNOME_BACKGROUND_FILE){
try{
$backgrounds_xml = @new SimpleXMLElement($file,null,true);
} catch (Exception $e){
echo "Couldn't open '$file' to get list of backgrounds\n";
die;
}
$backgrounds = $backgrounds_xml->xpath('wallpaper[@deleted="false"]');
shuffle($backgrounds);
return $backgrounds;
}

function setBackground(SimpleXMLElement $background){
$file = (string)$background->filename;
$options = (string)$background->options;
if(!file_exists($file)) return false;
exec( 'gconftool -s /desktop/gnome/background/picture_filename -t string "'.$file.'";'.
'gconftool -s /desktop/gnome/background/picture_options -t string "'.$options.'"');
return true;
}

do {
$backgrounds = getBackgrounds();
$backgrounds_exist = false;
foreach ($backgrounds as $background){
if(setBackground($background)){
$backgrounds_exist = true;
sleep(DELAY);
}
}
}while ($backgrounds_exist);
echo "None of the backgrounds could be found\n";

It could be tweaked relatively easily to take command line input and/or make use of the other elements available from the XML file, but, as it is, it does just enough for me. Hopefully someone will find it useful, even it's just as a base to customise to their needs.

Monday, 1 December 2008

Flash overlapping html elements

I don't have to change the Z-Index of flash animations very often, which is why I forget how to do it.

To fix it:
  • Add <param name="wmode" value="transparent"> to the OBJECT tag.
  • Add wmode="transparent" to the EMBED tag.
Found the solution (most recently) here.