Title: Re: A script for placing an mailing address into new Entourage X record It works now
Here is an updated version of the script, which now handles name, address, e-mail address, and telephone number, in a variety of formats:
(* Make new contact from selected text
Selection must contain, at a minimum, 2 lines:
FirstName LastName
email address
OR
FirstName LastName
City, State Zip
It can contain, optionally, one of these formats:
FirstName LastName [Required]
address line 1 (second line optional)
City, State Zip
FirstName LastName [Required]
address line 1 (second line optional)
City, State Zip
email address
FirstName LastName [Required]
address line 1
address line 2 (will be appended to line 1 in Entourage if included)
City, State Zip
email address
FirstName LastName [Required]
address line 1 (second line optional)
City, State Zip
telephone number (only digits, spaces, hyphens, and parentheses can be included)
FirstName LastName [Required]
address line 1 (second line optional)
City, State Zip
email address
telephone number (only digits, spaces, hyphens, and parentheses can be included)
If the contact name has more than 2 words, the last word will become
the last name, and the rest will be the first name. If both email address and telephone are
included, they can appear in either order.
*)
tell application "Microsoft Entourage"
set {addr, eml, telephone} to {"", "", ""}
set x to the selection
if (class of x) is in {text, Unicode text, string} then
-- Parse into lines
try
set input to paragraphs of x
if item -1 of input is "" then set input to items 1 thru -2 of input
set cnt to count input
set aLine to item 1 of input
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set firstname to words 1 thru -2 of aLine
set firstname to firstname as text
set AppleScript's text item delimiters to oldDelims
set lastname to word -1 of aLine
repeat with i from 2 to cnt
set aLine to item i of input
if cnt = 2 or ((cnt > 3) and (cnt ≤ (i + 2))) or (cnt = 3 and i = 3) then -- It is the last line or next to last
if aLine contains "@" then -- email address
set eml to aLine
else -- City, state, zip, or else telephone #
--Check if it is a phone number
set chs to every character of aLine
set isPhone to true
repeat with ch in chs
if ch is not in "0123456789-() " then
set isPhone to false
exit repeat
end if
end repeat
if isPhone then
set telephone to aLine
else
set temp to every word of aLine
set zp to item -1 of temp
set ste to item -2 of temp
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set cty to (get items 1 thru -3 of temp) as text
set AppleScript's text item delimiters to oldDelims
end if
end if
else
set addr to addr & aLine & " "
end if
end repeat
on error theErr
display dialog "Parsing error; problem with input format." & return & theErr
return
end try
else
display dialog "Please select the contact info and try again."
return
end if
set c to make new contact with properties {first name:firstname, last name:lastname, address:eml, main phone number:telephone}
set hm to home address of c
set street address of hm to addr
set city of hm to cty
set state of hm to ste
set zip of hm to zp
set home address of c to hm
open c
end tell
- Re: A script for placing an mailing address into new... Allen Watson
- Re: A script for placing an mailing address into... Charlie Fritzius
- Re: A script for placing an mailing address ... Paul Berkowitz
- Re: A script for placing an mailing addr... Charlie Fritzius
- Re: A script for placing an mailing... Max Manshel
- Re: A script for placing an mai... Charlie Fritzius
- Re: A script for placing an mai... Paul Berkowitz
- Re: A script for placing an mai... Charlie Fritzius
- Re: A script for placing an mai... Allen Watson
- Re: A script for placing an mai... Allen Watson
- Re: A script for placing an mai... Allen Watson
- Re: A script for placing an mai... Max Manshel
- Re: A script for placing an mailing address ... Allen Watson
- Re: A script for placing an mailing address ... Allen Watson
- Re: A script for placing an mailing address into... Barry Wainwright
- Re: A script for placing an mailing address ... Charlie Fritzius
- Re: A script for placing an mailing address into new Ento... zaqq
