I am trying to parse this data from the content of an email. It works as a standalone. But when I compose the script for the application - Entourage it won’t accept the delimiters. So it won’t get the phone number. Also the script looks quite nasty and it keeps giving me a headache! Is it possible to just select the items appearing after the categories. ie. Address, Phone, Date etc?
Membership No: 44
Address: everywhere
Phone: 00991784100102
Date: 01-11-2006
Many thanks -drPETE
-- from email extracts the name, uk phone number and details and adds them to the AB
tell application "Microsoft Entourage"
set MyDisplaySenders to {}
set unreadlist to messages of folder "Inbox" whose read status = untouched
repeat with MessID from 1 to (number of items of unreadlist)
set theMessage to item MessID of unreadlist
set membersName to the subject of theMessage
set sSender to sender of theMessage
set addrNick to address of sSender
set dispName to display name of sSender
--set a to the text of content of theMessage as text
set a to "Membership No: 44
Address: everywhere
Phone: 00991784100102
Date: 01-11-2006"
set text item delimiters to ":"
set bContent to text items 4 thru 4 of a --Just grab the first 3rd line, using the colons as delimiters
set text item delimiters to ""
set bNumber to bContent --grab the just the number
set final_text to bNumber as text --Make the string from the grabbed items.
--set text item delimiters to tdl
set final_number to (characters 1 thru 16 of final_text) as text
set tPhone to final_number
set ukPhone to ("+44" & characters 1 thru 16 of tPhone) as string
set tLabel to ("Telephone") as Unicode text
set tNote to the content of displayed message
tell application "Address Book"
-- Make new record with members details in the note
set newPerson to make new person with properties {first name:(word 1 of membersName), last name:(word -1 of membersName), nickname:(word 1 of addrNick & " " & addrNick), note:"Hi " & (word 1 of dispName) & ", " & "your membership details:- " & tNote as Unicode text}
-- Add the phone number.
tell newPerson to make new phone at end of phones with properties {label:tLabel, value:ukPhone}
save addressbook
end tell
end repeat
end tell