Entourage Script to modify phone numbers

A

Alastair McLachlan

Does anyone know of a script that will examine all my contacts, and
modify all phone numbers, be they work, mobile, fax etc etc; where
there is a "+" at the beginning of the number, make no changes; where
there is no "+" at the beginning, add a single "+" to the beginning of
the number.

Thanks,
Alastair
 
P

Paul Berkowitz

Does anyone know of a script that will examine all my contacts, and
modify all phone numbers, be they work, mobile, fax etc etc; where
there is a "+" at the beginning of the number, make no changes; where
there is no "+" at the beginning, add a single "+" to the beginning of
the number.


Here you go. Copy and paste it into Script Editor
(/Applications/AppleScript/) and click Compile.

To save it to use again, save it as a Script (the default) in the Entourage
Script Menu Items folder of Microsoft User Data folder (in ~/Documents of
your OS X user) - it will then be available in the Entourage script menu.


---------- Prefix + to Phones --------------

tell application "Microsoft Entourage"
set cl to every contact whose home phone number ‚ "" and home phone
number does not start with "+"
repeat with c in cl
tell c to set home phone number to ("+" & (get home phone number))
end repeat

set cl to every contact whose other home phone number ‚ "" and other
home phone number does not start with "+"
repeat with c in cl
tell c to set other home phone number to ("+" & (get other home
phone number))
end repeat

set cl to every contact whose home fax phone number ‚ "" and home fax
phone number does not start with "+"
repeat with c in cl
tell c to set home fax phone number to ("+" & (get home fax phone
number))
end repeat

set cl to every contact whose business phone number ‚ "" and business
phone number does not start with "+"
repeat with c in cl
tell c to set business phone number to ("+" & (get business phone
number))
end repeat

set cl to every contact whose other business phone number ‚ "" and other
business phone number does not start with "+"
repeat with c in cl
tell c to set other business phone number to ("+" & (get other
business phone number))
end repeat

set cl to every contact whose business fax phone number ‚ "" and
business fax phone number does not start with "+"
repeat with c in cl
tell c to set business fax phone number to ("+" & (get business fax
phone number))
end repeat

set cl to every contact whose mobile phone number ‚ "" and mobile phone
number does not start with "+"
repeat with c in cl
tell c to set mobile phone number to ("+" & (get mobile phone
number))
end repeat

set cl to every contact whose assistant phone number ‚ "" and assistant
phone number does not start with "+"
repeat with c in cl
tell c to set assistant phone number to ("+" & (get assistant phone
number))
end repeat

set cl to every contact whose main phone number ‚ "" and main phone
number does not start with "+"
repeat with c in cl
tell c to set main phone number to ("+" & (get main phone number))
end repeat

set cl to every contact whose pager phone number ‚ "" and pager phone
number does not start with "+"
repeat with c in cl
tell c to set pager phone number to ("+" & (get pager phone number))
end repeat

set cl to every contact whose custom phone number one ‚ "" and custom
phone number one does not start with "+"
repeat with c in cl
tell c to set custom phone number one to ("+" & (get custom phone
number one))
end repeat

set cl to every contact whose custom phone number two ‚ "" and custom
phone number two does not start with "+"
repeat with c in cl
tell c to set custom phone number two to ("+" & (get custom phone
number two))
end repeat

set cl to every contact whose custom phone number three ‚ "" and custom
phone number three does not start with "+"
repeat with c in cl
tell c to set custom phone number three to ("+" & (get custom phone
number three))
end repeat

set cl to every contact whose custom phone number four ‚ "" and custom
phone number four does not start with "+"
repeat with c in cl
tell c to set custom phone number four to ("+" & (get custom phone
number four))
end repeat

beep
display dialog "All done!" buttons {"OK"} default button 1 with icon 1
end tell

---------------------end script -----------------

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
C

Craig Deutsch

Nice, Paul. Wondering if you would be willing to modify that script such
that I can resolve a little consistency problem I also have with my phone
numbers.

By default, I have Entourage format new entries this way: ZZZ/XXX-XXXX (as
opposed to the usual (Area Code) XXX-XXXX format). I actually like the
former, but I have tons of old, imported contacts with the conventional
method applied. I use the slash-method because when entering data first
into my Palm, it¹s considerably easier.

Is this easy to do in the same fashion as for Mr. McLachlan such that all
phone numbers are examined?

If you don¹t have time, don¹t sweat it. If so, however, I¹m most
appreciative.

I promise to study your result and use is as a model for my own AppleScript
edjamakation. :)

Craig Deutsch
San Diego
 
P

Paul Berkowitz

Nice, Paul. Wondering if you would be willing to modify that script such that
I can resolve a little consistency problem I also have with my phone numbers.

By default, I have Entourage format new entries this way: ZZZ/XXX-XXXX (as
opposed to the usual (Area Code) XXX-XXXX format). I actually like the
former, but I have tons of old, imported contacts with the conventional method
applied. I use the slash-method because when entering data first into my
Palm, it¹s considerably easier.

Is this easy to do in the same fashion as for Mr. McLachlan such that all
phone numbers are examined?
First insert a new line, just once under the first 'tell application' line"

tell application "Microsoft Entourage"
set AppleScript's text item delimiters to {")"} -- THE NEW LINE



Then, you'll notice that there are 14 different phone types, all following
this model for home phones:

set cl to every contact whose home phone number ‚ "" and home phone
number does not start with "+"
repeat with c in cl
tell c to set home phone number to ("+" & (get home phone number))
end repeat



Change that to the following:

set cl to every contact whose home phone number starts with "("
repeat with c in cl
tell c
set ph to home phone number
set {areaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set home phone number to (areaCode & "/" & phoneNumber)
end tell
end repeat



Then make exactly the same adjustments in the other 13 phone types : note
that the expression home phone number occurs three times. You need to change
it all three times for each of the 13 phone types. Otherwise the fragment
should be identical for all 14 types.

Then insert one extra line before the final 'end tell' last line:

set AppleScript's text item delimiters to {""}
end tell

This will get phone numbers also where you may have forgotten to insert a
space between (area code) and the number.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
C

Craig Deutsch

Thanks, Paul, for doing that. However, I still have several hundred entries
that are odd ‹ though most of them are correctly fixed. Most of the wrong
ones have a leading ³(³, while a few still have a leading ³{³ before the
phone number.

What did I do wrong, and how can I universally fix it? The script I used is
below.

Any time you have to help is appreciated.

Thanks.

Craig
San Diego

----------------------

tell application "Microsoft Entourage"

set AppleScript's text item delimiters to {")"}

set cl to every contact whose home phone number starts with "("
repeat with c in cl
tell c
set ph to home phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set home phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose other home phone number starts with "("
repeat with c in cl
tell c
set ph to other home phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set other home phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose home fax phone number starts with "("
repeat with c in cl
tell c
set ph to home fax phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set home fax phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose business phone number starts with "("
repeat with c in cl
tell c
set ph to business phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set business phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose other business phone number starts with
"("
repeat with c in cl
tell c
set ph to other business phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set other business phone number to (AreaCode & "/" &
phoneNumber)
end tell
end repeat

set cl to every contact whose business fax phone number starts with "("
repeat with c in cl
tell c
set ph to business fax phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set business fax phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose mobile phone number starts with "("
repeat with c in cl
tell c
set ph to mobile phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set mobile phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose assistant phone number starts with "("
repeat with c in cl
tell c
set ph to assistant phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set assistant phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose main phone number starts with "("
repeat with c in cl
tell c
set ph to main phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set main phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose pager phone number starts with "("
repeat with c in cl
tell c
set ph to pager phone number
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set pager phone number to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose custom phone number one starts with "("
repeat with c in cl
tell c
set ph to custom phone number one
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set custom phone number one to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose custom phone number two starts with "("
repeat with c in cl
tell c
set ph to custom phone number two
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set custom phone number two to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose custom phone number three starts with "("
repeat with c in cl
tell c
set ph to custom phone number three
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set custom phone number three to (AreaCode & "/" & phoneNumber)
end tell
end repeat

set cl to every contact whose custom phone number four starts with "("
repeat with c in cl
tell c
set ph to custom phone number four
set {AreaCode, phoneNumber} to ph's {text item 1, text item 2}
if phoneNumber starts with " " then set phoneNumber to text 2
thru -1 of phoneNumber
set custom phone number four to (AreaCode & "/" & phoneNumber)
end tell
end repeat

beep
display dialog "All done!" buttons {"OK"} default button 1 with icon 1
set AppleScript's text item delimiters to {""}
end tell
 
Top