Periodically changing desktop wallpaper using Ruby

Posted on November 27, 2007. Filed under: XP, ruby, software, vista, windows |

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.

Make a Comment

Make a Comment: ( 2 so far )

blockquote and a tags work here.

2 Responses to “Periodically changing desktop wallpaper using Ruby”

RSS Feed for Blogging on Technology Comments RSS Feed

Nice script….:)

Thanks, Arjun :)


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...