2004 SP2 Address Book - Searching and Replacing

B

blakemcc

I am using Office 2004 SP2 under 10.4.2 with all software and security
updates and am not having any operational issues.

However, I have been scouring the internet trying to find an
Applescript or other method for doing search-and-replace in my
Entourage Address Book. My address book contains abot 4,000 records.

Two examples of the type of change I would like to perform are:

- Unify the appearance of phone numbers; many have the +1 prefix which
I would like to lose; also, if possible, I would like to delete
parentheses around area codes.

- In this world of mergers and conglomerations, many of my contacts
have had their companies' names changed; and to complicate matters,
it's not always a straight name change but the addition of a parent
company name before other subsidiary company names. In Word or Excel,
it's a simple search-and-replace of a text string; in Entourage ...?

I tried exporting my address book as a text file, using Excel to make
changes, and then re-importing it to a new identity but things are
lost/introduced in the translation.

Thanks in advance for any help.

Blake
 
B

blakemcc

This is the sound of one person posting (replying to my own post...)

The script that I located in the mail archives that comes closest (I
believe it was originated by Allen Watson) for phone number
re-formatting is below. Unfortunately, the the action in the script
called onlyDigits(s) does not know to strip out the initial 1 so the
result from running this script is 1AAAPPPNNNN instead of the desired
AAA PPP-NNNN. The other ideal change would be for the script to make
these changes in all telephone numbers for a contact.

Thanks in advance for any help!


tell application "Microsoft Entourage"
activate
try
set theList to the selection
on error theErr number errNum
if errNum = -1728 then
-- Try formatting the text on the clipboard
set t to the clipboard
set t to my reformat(t)
set the clipboard to t
try
set the selection to t
on error
display dialog "Clipboard now contains: " & t
end try
return
else
display dialog "Error number:" & errNum & " " & theErr
return
end if
end try
repeat with theC in theList
if class of theC is not contact then
if (class of theC is string) or (class of theC is Unicode
text) then
-- Try formatting the text on the clipboard
set t to the clipboard
set t to t as text
set t to my reformat(t)
set the clipboard to t
try
set the selection to t
on error
display dialog "Clipboard now contains: " & t
end try
return
end if
display dialog "No contacts are selected."
return
end if
-- set theC to contact "Jenna Burrell"
tell theC
set home phone number to my reformat(home phone number)
set business phone number to my reformat(business phone
number)
end tell
end repeat
end tell

on onlyDigits(s)
-- Strip all but digits from a string
set theDigits to "1234567890"
set newS to ""
repeat with i from 1 to length of s
set c to character i of s
if c is in theDigits then set newS to newS & c
end repeat
return newS
end onlyDigits

on formatNum(n)
-- Insert USA telephone formatting
--Choose one of two formats, comment out one unused
set mask to "AAA PPP-NNNN"
-- set mask to "AAA-PPP-NNNN"
if length of n is 10 then
set aaa to text 1 thru 3 of n
set ppp to text 4 thru 6 of n
set nnnn to text 7 thru 10 of n
set mask to my searchReplace(mask, "AAA", aaa)
set mask to my searchReplace(mask, "PPP", ppp)
set mask to my searchReplace(mask, "NNNN", nnnn)
set n to mask
else if length of n is 7 then
set n to text 1 thru 3 of n & "-" & text 4 thru 7 of n
end if
return n
end formatNum

on reformat(pNum)
set pNum to my onlyDigits(pNum)
set pNum to my formatNum(pNum)
return pNum
end reformat

-- routine to do a search and replace on text
on searchReplace(mainString, searchString, replaceString) --
Parameters: search, replace, the String
set olddelis to AppleScript's text item delimiters

set AppleScript's text item delimiters to (searchString)
set theList to (every text item of mainString)

set AppleScript's text item delimiters to (replaceString)
set theString to theList as string

set AppleScript's text item delimiters to olddelis
return theString
end searchReplace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top