Wednesday, February 13, 2008

Automating Google Earth (and Sky)

You know how it is, you're talking to someone over coffee about how things are possible, and the next day you're expected to know intimate technical details about exactly how to do it, and to get it done by close of business that day.

This happened to me at the tail end of last week and as a result I've been taking my first serious look at Applescript and Apple's Automator.

One of the things I needed to do was script Google Earth, and being an astronomer, what I really needed to do was be able to flip between Google Earth and Google Sky automatically. Unfortunately there wasn't anything in the Google Earth Action Pack that allowed me to do this, and Google Earth has a fairly thin Applescript dictionary.

Of course with the release of Mac OS X Panther, Apple introduced features into the System Events process which allows AppleScript to perform some actions in applications that have no, or only partial, built-in scripting support.



So I wrote some Applescripts to drive the Google Earth GUI, and allow me to flip between Earth and Sky modes, but people locally found the idea of Applescript to be a bit scary. So I went ahead and turned these scripts into Automator actions.

You'll notice that these actions use an Applescript delay to wait for image streaming from the server to complete, rather than the built in GetStreamingProgress function. Unfortunately I've not found this function to be terribly reliable, about one time in five it'll get stuck and never report that streaming has completed. This isn't terribly helpful if you need reliable scripts, so I've gone with a delay.

You can download the two automator actions I wrote to switch Google Earth between Earth and Sky modes. If you place these into either /Library/Automator/ or ~/Library/Automator they will show up automatically next time you run Automator, associated with Google Earth. Remember that because these actions reply on System Events you'll need to enable enable UI scripting in the System Preferences before they'll work for you.