on run -- testing routine set theParameters to {50, 1, "unknown", "unknown", "unknown", "unknown"} handleTheParameters(theParameters) end run -- This routine is called when the OS is asked to parse a 'geoloc' URL. on open location geolocURI -- display dialog "The entire URI is " & geolocURI set refPart to text 8 through -1 of geolocURI -- display dialog "The reference part is " & refPart set paramArray to splitTextBy(refPart, ",") -- display dialog "The parameter array supplied is " & paramArray -- display dialog "The count of the parameters is " & the length of paramArray set paramAttay to addMissingParameters(paramArray) -- display dialog "The six parameters are " & paramArray -- display dialog "The count of the parameters is now " & the length of paramArray set paramAttay to cleanParameters(paramArray) handleTheParameters(paramArray) end open location -- This routine does the desired operation. on handleTheParameters(paramArray) set {latitude, longitude, altitude, radius, direction, tilt} to paramArray -- For this demonstration, the routine does one of two things: -- If Google Earth is running it shifts its view to the indicated location. -- Otherwise it brings up a Google Map showing the location. tell application "Google Earth" to set GERunning to it is running if GERunning then -- here is an example which uses Google Earth set myLat to latitude set myLon to longitude tell application "Google Earth" -- modify existing view so as to keep user's preferred angle, zoom, etc. set theViewInfo to GetViewInfo set latitude of theViewInfo to myLat set longitude of theViewInfo to myLon SetViewInfo theViewInfo -- this could be expanded to draw a circle around the radius -- or a 3D arrow pointed in the direction and tilt end tell else -- Here is simpler example for how to respond to the URI tell application "Finder" to open location "http://maps.google.com/?ll=" & latitude & "," & longitude & "&z=11&t=p" end if end handleTheParameters ------------------------------ functions ---------------------------------- on addMissingParameters(paramArray) set soFar to paramArray if the length of soFar < 1 then copy "" to the end of soFar if the length of soFar < 2 then copy "" to the end of soFar if the length of soFar < 3 then copy "" to the end of soFar if the length of soFar < 4 then copy "" to the end of soFar if the length of soFar < 5 then copy "" to the end of soFar if the length of soFar < 6 then copy "" to the end of soFar set soFar to items 1 through 6 of soFar return soFar end addMissingParameters -- This routine should clean up parameters which are required for the preferred operation. -- For instance, it should spot non-numeric or missing required parameters and warn the user. on cleanParameters(paramArray) return paramArray end cleanParameters ------------------------- utility functions ------------------------------- -- This function is the equivalent of the 'split' or 'explode' function you find -- in most languages. It turns a string into an array of substrings. on splitTextBy(theText, theSplitter) set soFar to {} set textRemaining to theText repeat until (the offset of theSplitter in textRemaining) = 0 -- copy off the first of the remaining parameters set splitStart to the offset of theSplitter in textRemaining if splitStart = 1 then copy "" to the end of soFar else copy text 1 through (splitStart - 1) of textRemaining to the end of soFar end if -- now remove that parameter from the beginning of textRemaining set afterSplit to splitStart + the (length of theSplitter) set textRemaining to substringFrom(textRemaining, afterSplit) end repeat -- copy off any remaining parameters copy textRemaining to the end of soFar return soFar end splitTextBy -- This is a substitute for AppleScript's 'text a through z of s' function which is broken. on substringFrom(theText, theStart) if theStart ≤ the length of theText then return text theStart through -1 of theText else return "" end if end substringFrom