Periodically changing desktop wallpaper using Ruby
Here is small ruby script that picks up a random image from a given folder and sets it as the desktop wallpaper.
1: require 'Win32API'
2:
3: SPI_SETDESKWALLPAPER = 20
4: SPIF_SENDCHANGE = 0x2
5: SOURCE_FOLDER = "C:\\Users\\Gaurav\\Pictures\\Best\\"
6:
7: files = Dir.entries(SOURCE_FOLDER) - [".", ".."]
8: file = files[rand(files.length)]
9:
10: systemParametersInfo = Win32API.new("user32","SystemParametersInfo",["I", "I", "P", "I"],"I")
11: p systemParametersInfo.call(SPI_SETDESKWALLPAPER, 1, SOURCE_FOLDER + file, SPIF_SENDCHANGE)
The constant SOURCE_FOLDER can be changed to point at the folder which contain all your wallpaper and the script then randomly chooses a wallpaper from the collection.
You can also set your task scheduler to run this script automatically after a fixed interval so that your desktop wallpaper keeps changing.
Here is the pastie.



Nice script….:)
Arjun
April 17, 2008
Thanks, Arjun
techblogger
April 17, 2008