J'essaie de substituer une adresse électronique à un caractère symbolique dans un bloc de texte.
Le bloc de texte :
Dear %%FirstName%%-
...
This message was sent to %%EmailAddress%%.
Le script :
...
set theBody to my replace(theBody, "%%FirstName%%", "First")
set theBody to my replace(theBody, "%%EmailAddress%%", "first.last@company.com")
...
Remplacer la sous-procédure ( AppleScript : Sous-routines essentielles ) :
on replace(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace
Le résultat :
Dear First-
...
This message was sent to .
Si je change le script en :
...
set theBody to my replace(theBody, "%%FirstName%%", "First")
set theBody to my replace(theBody, "%%EmailAddress%%", "first.lastATcompany.com")
Le résultat :
Dear First-
...
This message was sent to first.lastATcompany.com.
Qu'est-ce qui ne va pas avec la replace
sous-procédure ?
** modifier **
Je collecte une liste distincte d'adresses électroniques à partir d'un contact Outlook :
...
set theAddresses to email addresses of theContact
set addressList to {}
repeat with theAddress in the theAddresses
if addressList does not contain (address of theAddress) then
set addressList to addressList & (address of theAddress)
end if
end repeat
...
Puis en utilisant la liste :
...
repeat with theAddress in addressList
...
make new recipient at newMessage with properties {email address:{name:displayName of theContact, address:theAddress}}
...
end repeat
...