tell application "System Events"
tell process "Mail"
tell text field "To:" of window 1
if UI element 1 exists then
set theToRecipient to (value of UI element 1)
if (count words of theToRecipient) is greater than 0 then return word 1 of theToRecipient
end if
end tell
end tell
end tell
I’m using the app “Editeur de script” to test this script, (I’m french but I guess it’s “Script Editor” in english), and, my system is in French.
Maybe that’s the problem and I should replace the “To:” on the third line by “À :” which is what I see on the “To:” line in French?
Thank for your help and advices, if you need more details, let me know!
Cheers,
Pierre
Model: iMac
AppleScript: 2.4
Browser: Safari 601.1.56
Operating System: Mac OS X (10.10)
When we use GUI Scripting, it’s often useful to extract the localized strings from the applications resources as I do below.
tell application "Mail" to set TO_loc to localized string "ToIndicator"
log result (*À*)
tell application "System Events"
tell process "Mail"
set frontmost to true
tell window 1
set ToName to (get name of first text field whose name starts with TO_loc)
log result (*À :*)
end tell
tell text field ToName of window 1
if UI element 1 exists then
set theToRecipient to (value of UI element 1)
if (count words of theToRecipient) is greater than 0 then return word 1 of theToRecipient
end if
end tell
end tell
end tell
The first instruction tell application “Mail” to set TO_loc to localized string “ToIndicator”
extracts a localized string whose value is “TO” in English but is “À” in French.
As things aren’t simple in GUI Scripting area, we can’t build the name of the text field by ourselves because in English there is no space between the name and the trailing colon but there is one in French.
This is why I extract the localized name of the text field with : set ToName to (get name of first text field whose name starts with TO_loc)
When it’s done we may use the true name to trigger the text item.
Yvan KOENIG running El Capitan 10.11.0 in French (VALLAURIS, France) mardi 20 octobre 2015 09:52:54