Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

apx2001

macrumors newbie
Original poster
Jul 15, 2008
1
0
The script below does the following: it adds selected email addresses in mail to a group in the address book. this is done based on the sender (see text in bold). However, I want to modify this script that the recipients are added. Please help!

Thank you!!!
johannes

/////////////////



set baseList to {}
set nameList to {}
set emailList to {}

-- get emails from "Mail"
tell application "Mail"
set mess_list to selected messages of front message viewer
repeat with this_email in mess_list
set toEmail to extract address from (sender of this_email)
set toName to extract name from (sender of this_email)

if toEmail is equal to toName then set toName to ""
set end of emailList to toEmail
set end of nameList to toName
end repeat
end tell

-- add to address book
tell application "Address Book"
set groupNames to name of every group
set groupResponse to choose from list groupNames with prompt "Select group"
if groupResponse is false then return
set thegroup to item 1 of groupResponse
set thePeople to {}
repeat with i from 1 to count of emailList
set thisEAddr to my change_case((item i of emailList), 0)
ignoring case
set thePerson to (people whose value of every email contains thisEAddr)
end ignoring
if thePerson is {} then
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set firstName to ""
set lastName to ""
if (count of text items of (item i of nameList)) > 0 then
set lastName to last text item of (item i of nameList)
if (count of text items of (item i of nameList)) > 1 then
set firstName to first text item of (item i of nameList)
end if
end if
set thePerson to make new person at end of people with properties {first name:firstName, last name:lastName}
tell thePerson to make new email at end of emails with properties {label:"work", value:thisEAddr}
else
set thePerson to item 1 of thePerson
end if
add thePerson to group thegroup
end repeat
save addressbook
end tell

on change_case(this_text, this_case)
if this_case is 0 then
set the comparison_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set the source_string to "abcdefghijklmnopqrstuvwxyz"
else
set the comparison_string to "abcdefghijklmnopqrstuvwxyz"
set the source_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end if
set the new_text to ""
repeat with this_char in this_text
set x to the offset of this_char in the comparison_string
if x is not 0 then
set the new_text to (the new_text & character x of the source_string) as string
else
set the new_text to (the new_text & this_char) as string
end if
end repeat
return the new_text
end change_case
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.