Periodically changing desktop wallpaper using Ruby

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

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.

Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

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...

%d bloggers like this: