So, I made some changes recently to which computer I use for certain activities, and now there’s a gaming PC (hence, Zbox — more on that later). Win2k’s standard background settings didn’t quite do what I wanted, so I quickly threw together a web page that does. The actual images mostly come from Custer’s Desktops. Here’s the code:
function loaded() {
var info = document.all.infoBlock,
path = "C:\\Documents and Settings\\Game Wonk\\My Documents\\My Pictures",
fs = new ActiveXObject("Scripting.FileSystemObject"),
folder = fs.GetFolder(path);
info.innerHTML = "Path " + folder.Path + "<br />";
info.innerHTML += "Size: " + folder.Size / 1024 + " Kb" + "<br />";
for (var fc = new Enumerator(folder.Files) ; !fc.atEnd() ; fc.moveNext()) {
if (fc.item().Name == "Desktop.ini")
continue;
images[images.length] = fc.item().Path;
info.innerHTML += fc.item().Name + "<br />";
}
setTimeout('choose()', 0);
}
function choose() {
try {
document.body.background = images[Math.floor(Math.random() * images.length)];
setTimeout('choose()', 90000);
} catch (e) {
alert(e.description);
}
}
window.onload = loaded;
{: lang=javascript }
The HTML of the rest of the page is trivial (there’s a CSS block to hide that info blurb when it isn’t needed). You’ll have to do something to tell IE to let the page load controls not marked as safe, and that much is left as an exercise. (The only reason I didn’t just put a list in was so I wouldn’t have to later edit it).
Updates
- Fixed the link in the first paragraph to…uh…be a link.
- The line-break tags in the code were getting escaped one too many times (in my original, rightly or wrongly, the tag appears as a string literal unescaped).