Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Check the status of the online Apple Store via shell script UNIX
Sometimes, like today, I'm particularly interested in the Apple Store's status...as in, when is it back up so that I can order whatever it is I'm waiting to order. While sitting around pressing Command-R this morning, I figured there must be a better way. After a few minutes with curl and GeekTool, I had the solution.

Because I didn't have very much time to implement this trick this morning, I just created a new 'Shell' Geeklet in GeekTool, with the refresh set to every five seconds, that showed the output of this command:

curl -s http://store.apple.com/us | grep backsoon | grep australia

Note that the above is specific both to the US Apple Store, and to the current version of that store. You may have to modify it for other geographies, or for future store site changes. Basically, what the command does is grab the Apple Store page via curl, suppresses the normal output (-s), and then searches for backsoon, which is the name of the GIF image Apple uses for the "We'll be back soon!" graphic.

There are, however, lots of matches for backsoon, so I then grep again for australia, which was the first occurrence of backsoon in the output. This way, I get just one line of output when the store is down. When it's up, there shouldn't be any output.

Testing was real world, too, as I waited for the 5:30am scheduled store opening. About a minute before that, the output from my Geeklet suddenly went blank, so I reloaded the web page, and there was the store. Nifty. For longer-term use, though, my solution leaves much to be desired. So after ordering the iPad, I turned my quick solution into a slightly more robust script that uses Growl to put the alert onscreen. Read on for that version.

I created the following script, which I named storecheck, in my user's bin folder:
#! /bin/bash
MYVAR=`curl -s http://store.apple.com/us | grep backsoon | grep australia`
if [ "$MYVAR" = "" ]
then
  if [ ! -f "/tmp/storeup.txt" ];     
  then
    growlnotify "The Store is up!" -m "Go buy whatever it was you were waiting for!"
    echo "1" > /tmp/storeup.txt
  fi
fi
The MYVAR line puts the output of the original command into a variable. It will either contain one line (when the store is down), or it will be empty (when the store is up). The next line checks to see if MYVAR is empty. If it is (the store is up!), it then checks for the existence of a file in the /tmp directory -- this file will only exist once the Growl alert has been displayed one time.

Assuming the file isn't found, the script then displays the Growl notification, and creates the file in the /tmp directory. The next time the script runs, it won't display another Growl alert, because of the file in /tmp (which gets erased automatically on your next restart).

I set the script to executable (chmod a+x storecheck), and now it's ready for use in the future. I can either create a cron or launchd task to run it every nn seconds, or create a GeekTool Geeklet that runs the script -- which is probably the route I'll take if I need to use it again.

Once the Growl alert appears, I'll need to disable the Geeklet by hand, but that's not too hard to do. (I'm not sure if you can programmatically disable Geeklets or not. You could do it with a cron task, but I'll leave that as an exercise for readers.)
    •    
  • Currently 3.08 / 5
  You rated: 2 / 5 (13 votes cast)
 
[8,795 views]  

Check the status of the online Apple Store via shell script | 3 comments | Create New Account
Click here to return to the 'Check the status of the online Apple Store via shell script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Check the status of the online Apple Store via shell script
Authored by: gcthompson on Mar 12, '10 11:27:51AM

You clearly have too much money :-)



[ Reply to This | # ]
Check the status of the online Apple Store via shell script
Authored by: robg on Mar 12, '10 08:36:48PM

Hehe. Oddly, I didn't even really want an iPad. However, for the new role at Many Tricks, one is basically required, given some upcoming projects.

-rob.



[ Reply to This | # ]
Check the status of the online Apple Store via shell script
Authored by: BiL Castine on Mar 13, '10 09:28:44AM
You can put the Geeklet in a group by itself, then enable or disable the group from the Geektool menu.

You could also use an AppleScript:
tell application "Geektool"
   set visible of group "AppleStoreStatus" to true
end tell


[ Reply to This | # ]