Hi all I hope you guys are well,
A problem I am facing is how to extract the first part of an email, which is the first name, from a longer string. The following is what I mean:
“Wayne Industries, bruce.wayne@wayneindustries.org, Away” → return “Bruce”
While searching in the forum (I am new here) I have come across a very remarkable 14 year old script from Marc hunte (he rocks!), that still works well and almost brings me there until one problem stated after this.
The brilliant script goes as follows:
set txt to {"Natalia ferrara 077559 020 8946 66003 bruce.wayne@wayneindustries.or", "Fan Boy bruce.wayne@wayneindustries.or 077559 020 8946 66003 byrens "}
set AddressList to {}
repeat with i from 1 to number of items in txt
set AppleScript's text item delimiters to {"@"} --sets new dilm
set this_txt to item i of txt
set right_txt to word 1 of text item -1 of this_txt
set left_txt to word -1 of text item 1 of this_txt
set AppleScript's text item delimiters to "" -- resets dilm
copy left_txt & "@" & right_txt as string to end of AddressList
end repeat
return item 1 of AddressList
But HOW do I get now the FIRST PART of that e-mail out of strings like that:
“Bruce Wayne, bruce.wayne@wayneindustries.org, Away” → return “Bruce”
“bruce.wayne@wayneindustries.org, Away” → return “Bruce”
“Industries, bruce.wayne@wayneindustries.org, Here” → return “Bruce”
if there is no “.” then → “Industries, wayne@wayneindustries.org, Here” → return “Wayne”
What i wish the script would be structured, would be more or less like this:
1) check if there is an “@” in the string.
2) take the word left to the “@”, the first part of the email address → “bruce.wayne” or “wayne”
3) IF there is a “.” take the first name if not the the full name → “bruce”
4) Make the first letter a capital → “Bruce”
5) return “Bruce” as a variable
I’m not sure how to get there, since this is way over my head. Any help from you pros with this would be much appreciated.
Best wishes and many thanks for your help in this!