APOD celebrates 15 years

June 16, 2010 09:23 by scibuff

On June 16, 1995 NASA and Michigan Technological University (MTU) launched a new website called The Astronomy Picture of the Day (APOD). APOD was presented at a meeting of the American Astronomical Society in 1996. It received a Scientific American Sci/Tech Web Award in 2001.

APOD is 15 years old

Whimsical Vermeer composite that ran on APOD's fifth anniversary now digitally re-pixelated using many of the over 5,000 APOD images that have appeared over APOD's tenure

As during each of the 15 years of selecting images, writing text, and editing the APOD web pages, the occasionally industrious Robert Nemiroff (left) and frequently persistent Jerry Bonnell (right) are pictured above plotting to highlight yet another unsuspecting image of our cosmos. Although the above image may appear similar to the whimsical Vermeer composite that ran on APOD’s fifth anniversary, a perceptive eye might catch that this year it has been digitally re-pixelated using many of the over 5,000 APOD images that have appeared over APOD’s tenure.

It was a great honor to have a link to my blog post appear in the APOD website on October 15, 2009; you may remember:

Extremely bright fireball seen over the Netherlands

The brilliant fireball meteor captured in this snapshot was a startling visitor to Tuesday (October 13, 2009) evening's twilight skies over the city of Groningen - Credit: Robert Mikaelyan

Set APOD and AAPOD as your Desktop Pictures

November 10, 2009 19:36 by scibuff

Download my APOD AAPOD Desktop application.

Some time ago I wrote a little batch script that downloads the most recent Astronomy Picture Of Day (APOD) and sets it as your desktop wallpaper (on a Windows system). This time, I’ve improved on it a bit. First of all, it’s a for OSX (tested on OSX 10.5.8). But the major improvement is that apart from an APOD image, it also downloads the Amateur Astronomy Picture Of Day (AAPOD) which it then sets as the Desktop Picture on my second screen.

Unlike for the Windows app, there is no need for any additional libraries (such as wget, grep, etc for win32) as a typical OSX installation has all necessary tools (curl and perl are required, but should be installed under the majority of installation settings). The main script, wallpaper.pl, that does all the hard work is written in Perl using its powerful text processing capabilities. The other core file, named setdesktop.sh, is just a simple applescript (executed via shell) that sets the Desktop Pictures for my two screens.

The wallpaper.pl is based on Harold Bakker’s APOD script. I have added some command line options and the bits to get the AAPOD image. By default, all images, both APOD and AAPOD, will be stored within the images directory (although this can be disabled via a command line option). When you unpack the application archive there will be two items. One is the apod_aapod.zip containing the necessary files and the other is the install.command*.

The install.command is a simple shell script that sets everything up. It unpacks the contents of the apod_aapod.zip into the /Applications/APOD_AAPOD/ directory (which it creates if the directory doesn’t exists). During the installation the APOD_AAPOD.app application is created (by compiling plain AppleScript using osacompile). Finally, the script will add the newly created application to your Login Items so that your desktop pictures are updated every time you log in.

In the default setting, the application is meant to work with two monitors system. The APOD image will be set as the desktop picture on the main screen and the AAPOD will be set as the desktop picture on the second screen. To modify this behavior is fairly easy:

  1. Simply navigate to /Applications/APOD_AAPOD_Desktop/ directory and open the APOD_AAPOD.sh file.
  2. Scroll all the way down pass the comments to the last line that reads: perl wallpaper.pl -s -m 0 -n 2
  3. Read more about the available flags and what they affect in the few lines above (in the end of the comments under “Usage”):
    • – to reverse the APOD and AAPOD screens, i.e have the AAPOD image be set as the desktop picture on your main monitor, just add the ‘-r’ option, so that the line reads perl wallpaper.pl -s -m 0 -n 2 -r
    • – to prevent the application from storing the downloaded images, simply remove the ‘-s’ option
    • – If you have only a SINGLE monitor, you should change the value following the ‘-n’ option to ‘1’.
    • – If would like to only download the APOD or only the AAPOS image, change the value after ‘-m’ to 1 or 2, respectively.

To apply the changes, either wait until the next time you log, or run the “APOD_AAPOD” application.

* Note: The only reason is has the .command extension instead of the typical .sh is that so it can be executed by double-clicking on the file. If you prefer to run in via terminal, simply rename it to install.sh and run it via sh install.sh.

Download APOD and set it as the wallpaper batch script

May 14, 2009 14:25 by scibuff

Download my APOD Batch script.

If you never heard of APOD you’ve missed a lot in the last 14 years. The website, supported by NASA and Michigan Technological University, has published an image from the universe with a commentary by a professional astronomer every day since June 16, 1995.

I wanted an application which could download the APOD on daily basis and set it as my desktop wallpaper. There are a few tools out there that come close to the desired functionality. Most of them are free, but they all require admin/root rights on the machine and some don’t even seem to be 100% spyware-free. Thus, I’ve decided to create a simple batch script which would accomplish this task for me.

You may ask: Why bother creating an app if there already are similar ones out there? Well, usually I would say “don’t”. But, in this particular case, there actually wasn’t application which would work for me and/or had the functionality I was looking for. Besides, when it comes to programming, I like to do things myself. First, you always learn something new. Second, you can never be 100% sure that an executable does what it says it does. Sure, you can run tools such as TcpView and Process Explorer from SysInternals and see for yourself if anything wacky is happening behind the scenes, but by then you really are getting in too deep. I wanted just to download an image from the net and set it as a wallpaper for cryin’ out loud.

I like to have all my apps and code properly structured, so as the first step I created a new directory for my app (it doesn’t matter where). Inside, I created two directories: “bin” and “images” (I’ll come back to those a bit later), and my “apod.bat” batch file. I opened the batch in my favorite text editor (notepad) and typed @ECHO OFF at the first line and @ECHO ON at the end. Right after the first line I inserted the following:

REM create the image directory if it doesn't exist
IF NOT EXIST "images" mkdir "images"

REM is a “command” equivalent to the comment tag // in most modern languages. The line after that checks whether the directory called “images” exists and if not it creates it.

Now that I’m happy with the initial setup, I can proceed to the “real stuff”. Immediately from the beginning I knew there were four basic steps to the script:

1.) Read/download the most recent APOD HTML page
2.) Search through the APOD HTML page and find the image source path
3.) Download the APOD image
4.) Set the APOD image as the desktop wallpaper.

In linux, 1.), 2.) and 3.) are very easy – all you need is to pass the right arguments to the wget and grep commands.

wget is a simple yet powerful tool. I’m quite familiar with from the Linux environment so not even for a second did I look for a replacement on Windows, and went directly to GNU.org which provides most of the GNU core utilities for shell and text manipulation as Windows binary. The wget win32 binaries can be downloaded from the wget page. I will need the Binaries AND the Dependencies. After the packages were downloaded I unpacked them and place all binaries (*.exe and *.dll) into the “bin” folder created earlier. Then I repeat the same steps for the grep tool.

wget will take care of steps 1.) and 3.) and I’ll use grep for 2.). Now I just need a tool for 4.). This one takes a bit of looking around. It can be achieved directly with registry modification but then again it could run into the admin/root rights problems. I tried a few alternatives and the wallpaper changer from sg20.com had the best performance and 100% reliability. It does require .NET 2.0 framework but any up-to-date windows system has it already installed (as either a built-in or thru windows update) these days – in case you don’t, it can be downloaded from the msdn website. Once again, I downloaded the zip package and put the executable into the “bin” folder.

With all necessary tools ready in the “bin” folder I dove into the batch script itself. On the next line after the last edit, I added the following

REM download todays APOD html
bin\wget -N http://apod.nasa.gov/apod

The script above basically grabs the index.html from the APOD’s site (the -N flag ensures that the file is retrieved only if it is newer than the local copy). The index.html will contain the latest APOD image. The grep tool will search the html file using

REM get the big image url
bin\grep -o "image.*big.*jpg" index.html > images.txt

Most images on the APOD page are actually links to their largers sizes. The large images’ file names are usually of the format of <ImageName>_big.jpg. The line of code above searches the html source for image(s) names following this pattern. In general, grep outputs an entire line when a match was found. To restrict the output to the search pattern only I used the -o flag. Matches links are outputted into a temporary image.txt for later user. However, from time to time the big image name will not follow the above pattern (for example here). The few lines below will take care of that:

REM check if any images were found
COPY>nul images.txt nul |FIND "1 file(s) copied"

The code above investigates if any (big) images have been found in the APOD html by checking if the size of our images.txt is greater than 0.

REM if image(s) was/were found
IF NOT errorlevel=1 GOTO found

If the size is greater than 0, the script continues to the found label (oh boy, I’d flank my CS class if my teacher saw me using labels …)

REM images.txt has 0 size
IF errorlevel=1 GOTO not-found

If no images have been found, let’s just look for regular image names in the html files, i.e. not just the big ones.

REM get any type of image from the apod page
:not-found
bin\grep -o "image.*jpg" index.html > images.txt
goto found

After these few lines of code, we will have the APOD image filename(s) safely stored in the images.txt and we only need to download them.

I could just used the -i flag with wget to set images.txt as the input file. wget would simply run on every line of the file. Nevertheless, the line of code with grep looked only for image names, not full paths, so we need to add the path to the image directory. I used a simple FOR loop like so:

:found
REM download image(s)
FOR /F "tokens=*" %%G IN (images.txt) DO ( bin\wget -N "http://apod.nasa.gov/apod/%%G" )

Finally, the APOD image is downloaded, so I move it to the “images” folder as set it as the wallpaper

REM move image(s) to the image folder
FOR /F "tokens=*" %%G IN ('DIR /B *.jpg') DO (
MOVE "%%G" "images\%%G"
bin\WallpaperChanger.exe %~dp0images\%%G 1
)

DIR /B *.jpg lists all jpg’s in the current directory using the “bare” format (no heading information or summary).

The MOVE "%%G" "images\%%G" takes every match jpg’s and moves it into the “images” folder.

Finally bin\WallpaperChanger.exe sets the image as the desktop wallpaper. One important detail here is to use full path to the image. I can get the directory of the batch script using %~dp0 and adding images\%%G after that will do. I also specify 1 as the second parameter which stands for “Tiled” (1 is for Centered and 2 for Stretched) that sets the wallpaper settings.

As the very last step, I delete the temporary files the script used

DEL images.txt
DEL index.html

and the batch script is done. Here it is in its full:

@ECHO OFF

REM create the image directory if it doesn't exist
IF NOT EXIST "images" mkdir "images"

REM download todays APOD html
bin\wget -N http://apod.nasa.gov/apod

REM get the big image url
bin\grep -o "image.*big.*jpg" index.html > images.txt

REM check if any images were found
COPY>nul images.txt nul |FIND "1 file(s) copied"

REM download found images
IF not errorlevel=1 GOTO found

REM images.txt has 0 size
IF errorlevel=1 GOTO not-found

REM get any type of image from the apod page
:not-found
bin\grep -o "image.*jpg" index.html > images.txt
goto found

:found

REM download image(s)
FOR /F "tokens=*" %%G IN (images.txt) DO (
bin\wget -N "http://apod.nasa.gov/apod/%%G"
REM skip all other images
GOTO downloaded
)
:downloaded

REM move image(s) to the image folder
FOR /F "tokens=*" %%G IN ('DIR /B *.jpg') DO (
MOVE "%%G" "images\%%G"
bin\WallpaperChanger.exe %~dp0images\%%G 1
REM skip all other images
goto end
)
goto end

:end
DEL images.txt
DEL index.html

@ECHO ON

You can download the APOD batch (including the batch script, wget, grep and the WallpaperChanger tools) here.

Below is a list of some APOD applications for different platforms:

Windows

Pic APOD

OS X

Automatic APOD Desktop

Linux

APOD fetch shell script