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

Add a zip code lookup to Address Book Apps
I modified the Burger Locator script for Address Book to look up zip codes from the U.S. Post Office's Web site. Here's the modified version:

-- zip code locator
using terms from application "Address Book"
  on action property
    return "address"
  end action property
  
  on action title for p with e
    if zip of e is not missing value then
      return "Zip Code Present"
    else
      return "ZIP + 4 Lookup "
    end if
  end action title
  
  on should enable action for p with e
    if zip of e is missing value then
      return true
    else
      return false
    end if
  end should enable action
  
  on perform action for p with e
    set LookupURL to ¬
      "http://zip4.usps.com/zip4/zip4_responseA.jsp?Selection=1&address1=" ¬
      & street of e & "&city=" & city of e & "&state=" & state of e
    tell application "Dock" to open location LookupURL
    return true
  end perform action
end using terms from
You can also find the original, along with some discussion, here on my site.

[robg adds: Refer to the linked original hint for instructions on how to add this script to Address Book.]
    •    
  • Currently 2.20 / 5
  You rated: 1 / 5 (5 votes cast)
 
[20,970 views]  

Add a zip code lookup to Address Book | 14 comments | Create New Account
Click here to return to the 'Add a zip code lookup to Address Book' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Add a zip code lookup to Address Book
Authored by: sjonke on Nov 29, '04 11:10:20AM

That's pretty cool. I didn't know you could write plugins for Address Book in applescript. Are there are other applications that provide similar extendibility via applescript?

---
--- What?



[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: aschmidtm on Nov 29, '04 08:35:46PM

How about a reverse lookup to populate city by input of a zip code?

---
&nbsp[-[-[A]-]-]
SUBARU



[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: disappearinjon on Nov 30, '04 07:09:25PM
Here you go!
-- zip code reverse lookup
using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for p with e
		if city of e is missing value or state of e is missing value then
			return "Look up city and state"
		else
			return "City and State set"
		end if
	end action title
	
	on should enable action for p with e
		if ((zip of e is not missing value) and ((city of e is missing value) or (state of e is missing value))) then
			return true
		else
			return false
		end if
	end should enable action
	
	on perform action for p with e
		set LookupURL to "http://zip4.usps.com/zip4/zip_responseA.jsp?Selection=3&zipcode=" & zip of e
		tell application "Dock" to open location LookupURL
		return true
	end perform action
end using terms from


[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: jjmarcus on Nov 30, '04 12:53:09AM

Totally cool. Thanks!



[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: taxi on Dec 01, '04 05:27:03AM

And if you live in Australia, try the following: replace the LookupURL string to

"http://www1.auspost.com.au/postcodes/index.asp?Locality=" & city of e & "&sub=1&State=" & state of e & "&Postcode=&submit1=Search"

And it will go to the Australia Post website.

Next task: automatically put the data back into Address Book...



[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: rsnyder on Dec 19, '04 12:42:13AM

How would you modify the script to allow it to be used when the Zip is either null or = 5 digits. So that you can use the tool to find the Zip + 4 when you only have the short Zip code?

Right now I remove the short zip, click edit off, then the script becomes active. I am sure someone with more AppleScript experience can point me in the right direction.



[ Reply to This | # ]
ANSWER: Check for Zip +4 with only ZIP
Authored by: rsnyder on Dec 20, '04 10:02:23AM
Ok, so I'm answering my own question.

Provided you strictly follow the convention of using a hyphen in your Zip + 4 entries (e.g. #####-####) the following minor changes will allow you to look up the full Zip plus four even if you already have a five digit Zip in the field.

First, change the first part of the section for naming the action title to:
on action title for p with e
if zip of e contains "-" then
return "Zip Code Present"

Then change the first part of the section that enables the action title:
on should enable action for p with e
if zip of e does not contain "-" then
return true


[ Reply to This | # ]

Add a zip code lookup to Address Book
Authored by: Cimm on May 07, '05 06:52:11AM
If you would like to use this script with Belgian postcodes you may use this URL:
"http://postcode.nationaal.be/resultaat2.php?gem=" & city of e
It shows a webpage with the postcode of the city and the postcodes of the smaller communities in this area.

[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: rspeed on Oct 05, '05 12:00:19PM

It looks like USPS changed their web site causing this script to break. They are now using POST instead of GET for the request.

In addition, the script doesn't work on my machine at the moment. I modified it to tell Safari to open the address directly and it fixed the problem. I guess Tiger broke this.



[ Reply to This | # ]
Add a zip code lookup to Address Book
Authored by: bluehz on Feb 21, '07 11:45:29AM
Add a zip code lookup to Address Book
Authored by: Fofer on Apr 15, '08 08:51:41AM

The download link on that doesn't work any longer. Got another source?



[ Reply to This | # ]
UPDATED: Add a zip code lookup to Address Book
Authored by: joejoethedog on Dec 18, '08 07:42:02PM
As previously mentioned, the USPS changed their website code. Here is the script again with the updated URL. Also updated to open Safari directly and to allow for lookup if 5-digit Zip already there (from previous hints; thanks!)

-- zip code locator
using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for p with e
		if zip of e contains "-" then
			return "Zip Code Present"
		else
			return "ZIP + 4 Lookup "
		end if
	end action title
	
	on should enable action for p with e
		if zip of e does not contain "-" then
			return true
		else
			return false
		end if
	end should enable action
	
	on perform action for p with e
		set LookupURL to ¬
			"http://zip4.usps.com/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=" & street of e & "&address1=&city=" & ¬
			city of e & "&state=" & state of e & "&urbanization=&zip5=&submit.x=6&submit.y=15"
		tell application "Safari" to open location LookupURL
		return true
	end perform action
end using terms from
-Joe

[ Reply to This | # ]
UPDATED Feb 2012: Add a zip code lookup to Address Book
Authored by: dschargel on Feb 14, '12 12:07:55PM
Once again the USPS changed their website code, so here is the script again (building upon the previous hints) with the updated URL. Two versions: one to open with Safari and the second to open with Chrome.

Safari version…

-- zip code locator
using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for p with e
		if zip of e contains "-" then
			return "Zip Code Present"
		else
			return "ZIP + 4 Lookup "
		end if
	end action title
	
	on should enable action for p with e
		if zip of e does not contain "-" then
			return true
		else
			return false
		end if
	end should enable action
	
	on perform action for p with e
		set LookupURL to ¬
			"https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=0&companyName=&address1=" & street of e & "&address2=&city=" & ¬
			city of e & "&state=" & state of e & "&&urbanCode=&postalCode=&zip="
		tell application "Safari" to open location LookupURL
		return true
	end perform action
end using terms from

Chrome version…

-- zip code locator
using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for p with e
		if zip of e contains "-" then
			return "Zip Code Present"
		else
			return "ZIP + 4 Lookup "
		end if
	end action title
	
	on should enable action for p with e
		if zip of e does not contain "-" then
			return true
		else
			return false
		end if
	end should enable action
	
	on perform action for p with e
		set LookupURL to ¬
			"https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=0&companyName=&address1=" & street of e & "&address2=&city=" & ¬
			city of e & "&state=" & state of e & "&&urbanCode=&postalCode=&zip="
			tell application "Google Chrome"
				if not (exists first window) then
					make new window
					set URL of last tab of first window to LookupURL
				else
					tell first window
						set newTab to make new tab with properties {URL:LookupURL}
					end tell
				end if
				activate
			end tell
		return true
	end perform action
end using terms from


- David

[ Reply to This | # ]
UPDATED Feb 2012: Add a zip code lookup to Address Book
Authored by: odinsdad on Mar 08, '12 11:14:17AM

Awesome! I just updated this and it works great once again. It would be nice for it to just go fetch the Zip+4 and amend it automatically to the address book entry that the query came from instead of having to click edit, and type in the newly looked up zip+4 then click done.

Either way, beggars can't be choosers and thanks for getting this script updated so quickly.

~e

By the way, here is how to install the script instead of having people go find the original post...:

To install on your computer:
Copy the script above, between the dotted lines
Open /Applications -> AppleScript -> Script Editor.app
Paste the script into the top of a new script window
Save the script using these settings: Save As: ZipCodeLocator, Where: ~/Library -> Address Book Plug-Ins/; File Format: Script; Options: [x] Run only

Additional note:
If your on (OSX 10.7.x) Lion and can't find your Library folder because it's hidden by default go to the Finder -> Go -> Go to Folder...
type in ~/Library/ in the box and your home folder Library folder will open up for you...



[ Reply to This | # ]