10.3: Integrate maporama.com maps in Address Book

Nov 16, '03 12:23:00AM

Contributed by: vondrix

I prefer maporama.com to view maps, but the problem is that Address Book uses mapquest to show a map of an address. Thankfully, with Panther, the Adress Book is extendable by placing Applescripts in your ~/Library -> Address Book Plug-Ins folder.

Read the rest of the hint for the script and the how-to...


using terms from application "Address Book"
  on action property
    return "address"
  end action property
  
  on action title for aPerson with anAddress
    return "Maporama"
  end action title
  
  on should enable action for aPerson with anAddress
    return true
  end should enable action
  
  on perform action for aPerson with anAddress
    my showMap(street of anAddress, zip of anAddress, city of anAddress, ¬
      state of anAddress, country code of anAddress)
  end perform action
  
end using terms from

on showMap(street, zip, city, state, country)
  tell application "Safari"
    activate
    set map_doc to make new document at beginning of documents
    set the URL of map_doc to "http://www.maporama.com/share/map.asp"
    
    (* Wait till maporama is loaded in the webbrowser *)
    my waitForLoading(60)
    set map_doc to document 1
    
    (* Fill in the text fields *)
    do JavaScript "document.FindAdr._XgoGCAddress.value = '" & ¬
     street & "'" in map_doc
    do JavaScript "document.FindAdr.Zip.value = '" & zip & ¬
     "'" in map_doc
    do JavaScript "document.FindAdr.State.value = '" & state & ¬
     "'" in map_doc
    do JavaScript "document.FindAdr._XgoGCTownName.value = '" & ¬
     city & "'" in map_doc
    
    (* Find the country and select it *)
    set nbOfCountries to do JavaScript ¬
     "document.FindAdr.COUNTRYCODE.options.length" in map_doc
    repeat with i from 1 to nbOfCountries
      set iValue to do JavaScript ¬
     "document.FindAdr.COUNTRYCODE.options[" & i - 1 & "].value" in map_doc
      if iValue is country then
        set theIndex to i - 1
        exit repeat
      end if
    end repeat
    do JavaScript "document.FindAdr.COUNTRYCODE.options[" & ¬
     theIndex & "].selected = 1" in map_doc
    
    (* Submit the request *)
    do JavaScript "document.FindAdr.submit()" in map_doc
  end tell
end showMap

on waitForLoading(timeoutValue)
  tell application "Safari"
    delay 4
    repeat with i from 1 to timeoutValue
      delay 1
      if (do JavaScript "document.readyState" in document 1) is "complete" then
        exit repeat
      end if
    end repeat
  end tell
end waitForLoading
[robg adds: I had to control-click on the address field; hovering did nothing on my machine...]

Comments (21)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2003110614140491