May 102010

This isn’t just another “how to rotate your Windows Desktop image” post.  Search for that on Google and you will find many solutions for that.  I am going to show you how to use a specific image that is posted periodically to the web and have that as your desktop image.  For instance, let’s say your favorite cat photo website has a feature where they post the Cat Photo of the Day.  If they always post that image with the same file name (cpotd.jpg, perhaps), each day over-writing the image with the new image, then you could use that image as your windows desktop wallpaper, and whenever the photo is updated, you would have the latest photo on your desktop as well.  Now, there are RSS solutions to do something similar, but the difference here is that the file must always be named the same each time they update the photo.  Actually, this method is quite common for images that are updated periodically.  Many weather sites use the same image name for the latest weather map, for instance.  And many sites that do have a photo of the day feature as I described above use this method of updating their image.  Ready to do it yourself?

There are three parts to this.  First we need to identify an image that is suitable for our needs.   Remember, it must always have the same filename.  This method won’t work if today they name the image “20100509_cpotd.jpg” and tomorrow they name it “20100510_cpotd.jpg”.  Although with a little creative programming (perhaps using windows power shell), this could be worked around quite easily.  Step two involves writing a batch file and creating a shortcut to pull these steps into one small program. The final step will automate a means to download the updated images on schedule.

I am going to use an image from a very cool website,  This site displays an image of the earth rendered in real time, with a correct display for where it is daylight and evening.  It also shows the latest cloud cover.  It makes for a really cool image and it can easily be used for your desktop image.  But first, we need to make sure that the image filename is always the same.  Right click on the image and choose “Copy image URL”.  Then paste the image URL into the address bar of your browser and hit enter.  You should see a “web page” with nothing more than the image itself.  And we can now see the image URL,  Ok, it doesn’t look like they have any time or date strings in there, so my guess is, the filename is always the same.  But why is it named 1024.jpg?  1024 is a common width for desktop resolution, and is a common width for online images as well.  I wonder if a higher resolution is also available?  Let’s change the 1024 to 1600 and see what happens.  Sure enough, that gives us a larger image.  We will use as our source image.  Now, how often is the image updated?  Well, I have been looking at this site for a little while, and it would appear that the image is updated about every half hour.  I’ll keep that in mind as we go along.

Next, we need a means to automate the download and storage of the image.  I like a program called wget which is originally a command line tool for unix/linux just for retrieval of web pages and images.  It’s actually a quite powerful tool, and of course it is free and yes, there is a windows version available for us right here. After you are done with this exercise, I am sure you will find other uses for wget, such as backing up your website. Go ahead and install the windows binary for wget.  I used the “Complete package, except source” setup file.  If you prefer zipped files, go ahead and choose that.  When the installation is complete, wget should be installed in your c:\Program Files\GnuWin32\bin folder.  Open a command prompt by clicking on the start menu and typing “cmd” and pressing enter.  Then type

cd c:\Program Files\GnuWin32\bin

(here’s a hint:  try typing cd c:\Pro{Tab}\Gn{Tab}\bin{enter}).  Once you are in the correct folder, type


and press enter.  You should see wget do its thing and download the file.  The only trouble is, the file is downloaded to the current folder–not a really good thing to do.  Let’s make a folder just for our Earth Image and tell wget to store the image in that folder.  Make a suitable folder somewhere and name it something appropriate.  I used c:\users\skip\Pictures\EarthImage.  I would recommend using a path that has no spaces, like “My Pictures”.  Spaces can sometimes mess up automated programs like this.  Now that we have created that folder, let’s run wget again, this time using the -O option.  Option O tells wget where to store the output.  So the command this time will be: (type this command all on one line. Do not type the &&. That just shows that this line continues to the line below.)

wget -O C:\Users\skip\Pictures\EarthImage\earth.jpg &&

Note that I also changed the name of the file itself to earth.jpg.  Look in the folder and you should see our earth.jpg image, saved and ready to be used.  Now let’s see if we can apply that image as our wallpaper. I like a free program called “command line wallpaper changer portable”. Once it is installed, you just open a command prompt and enter

C:\Users\skip\CLWCP.exe C:\Users\skip\Pictures\EarthImage\earth.jpg

And you should see the image on your desktop. As you can see, I copied the executable clwcp.exe to my profile folder, but you can run it from wherever you want. If that works, step one is complete.

Step two is to automate the retrieval of these images. I want to do a few things to make the scheduling go easier and I also want to prevent the command prompt window from taking focus when it runs (I would like to update the wallpaper in the background without you really noticing that it is happening.) To do this, we will make a batch file called “GetEarthShot.bat” and save it somewhere like a utilities folder (I save mine in my profile folder, c:\users\skip). The batch file will only have two lines:

"C:\Program Files\GnuWin32\bin\wget.exe" -O C:\Users\skip\Pictures\EarthImage\earth.jpg
C:\Users\skip\CLWCP.exe C:\Users\skip\Pictures\EarthImage\earth.jpg

Can you see how it works? When this batch file runs, it will execute those two lines. First it will download the latest image. Then it will apply the image as the wallpaper. Save the file and double-click in in Explorer and you should see the command window pop up and see the two commands execute. Now, in order to make the command window itself NOT pop up (I find it distracting, and it can take the keyboard focus away), we will create a Windows shortcut to the batch file and set some properties to make sure it runs in the background. Right click on the GetEarthShot.bat file in Explorer and choose “Create Shortcut”. You should see the shortcut appear in explorer. Rename it so the “- Shortcut” isn’t there. I renamed mine to the same thing as the batch file itself: “GetEarthShot.bat”. Now right click on the shortcut and choose properties. You should see that the target is set to point to your batch file. Change the “Start in” parameter to “C:\Program Files\GnuWin32\bin\” (including the quotes). Finally set the “Run” parameter to “Minimized”. Click OK to save the changes and test it by double clicking the shortcut. If you watch VERY carefully, you might see the window pop up for a very, very brief moment, and then you may notice the icon on the task bar indicating that the batch file is running. After two or three seconds, the icon should go away and your desktop image should be updated. Now, if you are running this right away after initially setting the image when we first tested it, you may not be applying a NEW image, so you may not notice anything different. Step two is complete. Now let’s automate the whole process.

Go to Control Panel -> Administrative Tools -> Schedule Tasks.  On the left side, if you click on Task Scheduler Library, you will see all of your scheduled tasks in the center pane.  On the right, click on “Create Basic Task”.  I used “Update Earth Image” as the name and I gave it a nice description as well.  Click the “Next” button.  For the trigger, choose “After logon”.   Click “Next”.  Under “Action”, chose “Start a program”.  After clicking “Next” you will enter


And under “Start in”, enter

c:\Program Files\GnuWin32\bin\

Note that the full path to wget is in the command line.  Click “Next”.  Click to enable to “Open the properties dialog for this task when I click finish” and then click finish.  The properties dialog should pop up.  Click the Triggers tab and then “Edit”.  Under Advanced setting, click the “Repeat task every” and set the frequency to 30 minutes, for a duration of Indefinitely.  Click OK to exit and save the task.  This task should now run every 30 minutes.  So now, every 30 minutes, that folder will be updated with the latest earth image, over-writing the image already there.  If you right click on the task and choose “Run”, the task should run. You should see the batch file run minimized as we did before. If all is well, reboot your computer to get the task going. Step three is complete and you are done.

Using the process here, you could do a lot of things with wget setting up some cool rotating images. Good luck!

Leave a Reply