Address Book script contribution
Address Book script contribution
- Subject: Address Book script contribution
- From: Matt Petrowsky <email@hidden>
- Date: Wed, 5 Mar 2003 02:42:10 -0800
Since switching to Address Book I found that my collection of contacts
from over the years has every possible treatment of phone number
formatting.
So here is a nice script that will currently format your phone numbers
(10 digit US) into (xxx) xxx-xxxx format.
It will leave any number shorter or longer than 10 digits alone. Modify
as needed and enjoy.
--- snip ---
-- Routine for cleaning a text string into a number for formatting.
-- Uses coercion to Real to get only numbers
-- and bypass any periods, slashes, or other stuff.
on cleanNumber(theString)
set rawNumber to ""
repeat with i from 1 to count of theString
set x to character i of theString
try
x as real
if x is not "-" then
set rawNumber to rawNumber & x
end if
on error errString number errNumber
end try
end repeat
-- This is where you set your formatting of the number and default to
the supplied text if conditions are not met.
if length of rawNumber is 10 then
set myNumber to "(" & characters 1 thru 3 of rawNumber & ") " &
characters 4 thru 6 of rawNumber & "-" & characters 7 thru 10 of
rawNumber
else
return theString
end if
end cleanNumber
-- Main script starts here
tell application "Address Book"
repeat with CurrentPerson in people
repeat with thePhone in phones of CurrentPerson
set value of thePhone to my cleanNumber(value of thePhone)
end repeat
end repeat
end tell
Matt Petrowsky
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.