My script does not work!?

Hi,

i try to use this in Mail (via textexpander) - but it does not work on my system:
Mac OS Catalina - 10.15.4 (German language)

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) and (theToRecipient does not contain ",") then
				return word 1 of theToRecipient
			else if ((count words of theToRecipient) is greater than 0) and (theToRecipient contains ",") then
				return word 2 of theToRecipient
			end if
		end if
	end tell
end tell

end tell

When i run it in the scripteditor the answer is:

tell application “System Events”
exists UI element 1 of text field “To:” of window 1 of process “Mail”
→ false
end tell

any hinds
Many thx
Christoph

Model: MacBook Pro (Mitte 2015)
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

As you are running 10.14 (would work with 10.15 too)
you may use:

tell application "Mail"
	set x to "vcq-PD-mON.title"
	set to_loc to localized string x from table "ShareViewController"
end tell
if to_loc = x then set to_loc to "To:"
-- In Deutch it's "An:"

--------------------------------------------------------------------------------------------------
tell application "System Events"
	tell process "Mail"
		tell text field to_loc 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) and (theToRecipient does not contain ",") then
					return word 1 of theToRecipient
				else if ((count words of theToRecipient) is greater than 0) and (theToRecipient contains ",") then
					return word 2 of theToRecipient
				end if
			end if
		end tell
	end tell
end tell
--------------------------------------------------------------------------------------------------

I know someone doesn’t like these extraneous instructions but it’s not for pleasure that I give them frequently.
I know that there are users whose language is not English.
One may wish that such users would be able to see by themselves that, in their window, there is no text field entitled “To:” and that for Deutsch users, such field is entitled “An:” but most of them don’t know that.
This is why I do my best to give instructions able to localize the scripts on the fly.

With 10.14 and 10.15 it’s quite easy because if I remember well, only the English spelling is not reachable the standard way.
Under 10.13 it’s more complicated because several languages don’t give access to this string, English and French are two of them.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 19:12:48

Hi Yvan,

Thanks for your great support!
That was the first thing I checked. Even in different spellings.
Could it are still due to security settings or possibly extension that I use?

best regards
Christoph

=> The extensions are the problem (Daylite and Mailbutler).
Obviously, these prevent me from using the field.

I don’t find a window with the GUI structure that you try to drive.

I found one which behaves correctly with :

tell application "Mail"
	set x to "vcq-PD-mON.title"
	set to_loc to localized string x from table "ShareViewController"
end tell
if to_loc = x then set to_loc to "To:"
-- In Deutch it's "An:"
if (system attribute "sys2") as integer = 13 then set to_loc to "À :" -- to work on YK's imac
--------------------------------------------------------------------------------------------------
tell application "System Events" to tell process "Mail"
	set frontmost to true
	tell window 1
		class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, button, button, button, toolbar, group}
		name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
		value of text fields --> {"petit papa noël", "", "", "", ""}
		tell text field to_loc
			class of UI elements --> {}
			set theToRecipient to its value --> "petit papa noël"
			
			if ((count words of theToRecipient) ≥ 0) then
				if theToRecipient contains "," then
					return word 2 of theToRecipient
				else
					return word 1 of theToRecipient --> "petit"
				end if
			end if
		end tell -- text field
	end tell -- window 1
end tell -- System Events
--------------------------------------------------------------------------------------------------

I wonder how I have missed the fact that text fields doesn’t contain an UI element.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 19:34:54

To help you to trace what’s achieved, I split the instructions into single task ones.

Would be glad to know if the edited version works for you.

If it doesn’t, may you post the log history ?
I don’t know your extensions and I am surprised by the UI element which you try to trigger in the text field.
I never saw such element in a text field.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 11:47:07

Message from an angry man.
Trying to help I installed Daylite and Mailbutler.

No problem with Mailbutler but this shit named Daylite force Mail to quit.
Their technical service is unavailable
Their Help point to an unknown site
Maybe I’m blind but I saw no Uninstall option.
So I used brute force and trashed every item whose name contain Daylite.
Happily, it seems that the shit no longer strike.

With MailButler installed I discovered that the GUI of the window of new Mail document is not the standard one.
It’s not the one that ChristophWi tried to drive.
Here is what I got.

tell application "Mail"
	activate
	set x to "vcq-PD-mON.title"
	set to_loc to localized string x from table "ShareViewController"
end tell

if to_loc = x then set to_loc to "To:"
-- In Deutch it's "An:"

if (system attribute "sys2") as integer = 13 then set to_loc to "À :" -- to work on YK's imac
--------------------------------------------------------------------------------------------------
tell application "System Events"
	set theProcesses to name of processes
	
	tell process "Mail"
		set frontmost to true
		if theProcesses contains "MailButler" then
			tell window 1
				class of UI elements --> {splitter group, button, button, button, toolbar, group}
				tell splitter group 1
					class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, group, scroll area, pop up button, static text, splitter, group, group, group, group, radio group}
					name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
					value of text fields --> {"", "", "", "", ""}
					tell text field to_loc
						class of UI elements --> {text field}
						tell text field 1
							class of UI elements --> {}
							set theToRecipient to its value --> "petit papa noël"
							if ((count words of theToRecipient) ≥ 0) then
								if theToRecipient contains "," then
									return word 2 of theToRecipient
								else
									return word 1 of theToRecipient --> "petit"
								end if
							end if
						end tell
					end tell
				end tell
			end tell -- window 1
		else
			tell window 1
				class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, button, button, button, toolbar, group}
				name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
				value of text fields --> {"petit papa noël", "", "", "", ""}
				tell text field to_loc
					class of UI elements --> {}
					set theToRecipient to its value --> "petit papa noël"
					
					if ((count words of theToRecipient) ≥ 0) then
						if theToRecipient contains "," then
							return word 2 of theToRecipient
						else
							return word 1 of theToRecipient --> "petit"
						end if
					end if
				end tell -- text field
			end tell -- window 1
		end if
	end tell
end tell -- System Events
--------------------------------------------------------------------------------------------------

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 14:10:05

Recent infos.

I was contacted by Daylite support.
It’s surprising but it appeared that the Mailbutler version which I downloaded was not the more recent one so I downloaded again and this time I got version 2819 (13559).
It continue to conflict with Daylite version 2020.13 (5294).

With only MailButler installed the GUI of the message window is different from the one reported in message #6.
Here is a script matching the new GUI.

tell application "Mail"
	--activate
	set x to "vcq-PD-mON.title"
	set to_loc to localized string x from table "ShareViewController"
end tell

if to_loc = x then set to_loc to "To:"
-- In Deutch it's "An:"

if (system attribute "sys2") as integer = 13 then set to_loc to "À :" -- to work on YK's imac
--------------------------------------------------------------------------------------------------
tell application "System Events"
	set theProcesses to name of processes
	
	tell process "Mail"
		set frontmost to true
		if theProcesses contains "MailButler" then
			tell window 1
				class of UI elements ---> {splitter group, button, button, button, toolbar, group}
				tell splitter group 1
					class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, group, scroll area, pop up button, static text, splitter, group, group, group, group, radio group}
					name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
					value of text fields --> {"petit papa noël", "", "", "", ""}
					tell text field to_loc
						class of UI elements --> {}
						set theToRecipient to its value --> "petit papa noël"
						if ((count words of theToRecipient) ≥ 0) then
							if theToRecipient contains "," then
								return word 2 of theToRecipient
							else
								return word 1 of theToRecipient --> "petit"
							end if
						end if
					end tell
				end tell
			end tell -- window 1
		else
			tell window 1
				class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, button, button, button, toolbar, group}
				name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
				value of text fields --> {"petit papa noël", "", "", "", ""}
				tell text field to_loc
					class of UI elements --> {}
					set theToRecipient to its value --> "petit papa noël"
					if ((count words of theToRecipient) ≥ 0) then
						if theToRecipient contains "," then
							return word 2 of theToRecipient
						else
							return word 1 of theToRecipient --> "petit"
						end if
					end if
				end tell -- text field
			end tell -- window 1
		end if
	end tell
end tell -- System Events
--------------------------------------------------------------------------------------------------

Which may be shortened as :

tell application "Mail"
	--activate
	set x to "vcq-PD-mON.title"
	set to_loc to localized string x from table "ShareViewController"
end tell

if to_loc = x then set to_loc to "To:"
-- In Deutch it's "An:"

if (system attribute "sys2") as integer = 13 then set to_loc to "À :" -- to work on YK's imac
--------------------------------------------------------------------------------------------------
tell application "System Events"
	set theProcesses to name of processes
	
	tell process "Mail"
		set frontmost to true
		if theProcesses contains "MailButler" then
			set target to splitter group 1 of window 1
		else
			set target to window 1
		end if
		tell target
			class of UI elements
			-- without MailButler
			--> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, button, button, button, toolbar, group}
			-- with MailButler
			--> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, group, scroll area, pop up button, static text, splitter, group, group, group, group, radio group}
			name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
			value of text fields --> {"petit papa noël", "", "", "", ""}
			tell text field to_loc
				class of UI elements --> {}
				set theToRecipient to its value --> "petit papa noël"
				if ((count words of theToRecipient) ≥ 0) then
					if theToRecipient contains "," then
						return word 2 of theToRecipient
					else
						return word 1 of theToRecipient --> "petit"
					end if
				end if
			end tell -- text field
		end tell -- window 1
	end tell
end tell -- System Events
--------------------------------------------------------------------------------------------------

Again, the found GUI doesn’t match the one triggered by ChristophWi in its original message.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 19:33:31

New benefit of insomnia.
I made tests with Daylite installed (without Butler because under 10.13.6 they are conflicting).
I discovered that it introduced an extraneous of complexity in the GUI.
Here is what I got:

-- 4ChristopWi + Daylite
-- Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 02:13:34

tell application "Mail"
	--activate
	set x to "vcq-PD-mON.title"
	set to_loc to localized string x from table "ShareViewController"
end tell

if to_loc = x then set to_loc to "To:"
-- In Deutch it's "An:"

if (system attribute "sys2") as integer = 13 then set to_loc to "À :" -- to work on YK's imac
--------------------------------------------------------------------------------------------------
tell application "System Events"
	set theProcesses to name of processes
	
	tell process "Mail"
		set frontmost to true
		if theProcesses contains "Daylite" then
			tell window 1
				class of UI elements --> {splitter group, button, button, button, toolbar, group}
				tell splitter group 1
					class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, splitter, scroll area}
					name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
					--value of text fields 
					if value of text field to_loc is "" then
						--> {"", "", "", "", "Re: [Marketcircle Customer Service] #317784 - \"Ticket Updated!\" Re: Trying to help somebody I installed yor Daylite trial and now Mail crash at every opening Howmay I uninstall this garbage ?"}
						tell text field to_loc
							class of UI elements --> {text field}
							tell text field 1
								class of UI elements --> {}
								set theToRecipient to its value --> "petit papa noël"
								if ((count words of theToRecipient) ≥ 0) then
									if theToRecipient contains "," then
										return word 2 of theToRecipient
									else
										return word 1 of theToRecipient --> "petit"
									end if
								end if
							end tell
						end tell
					else
						--> {"petit papa noel", "", "", "", "Re: [Marketcircle Customer Service] #317784 - \"Ticket Updated!\" Re: Trying to help somebody I installed yor Daylite trial and now Mail crash at every opening Howmay I uninstall this garbage ?"}
						tell text field to_loc
							class of UI elements --> {}
							set theToRecipient to its value --> "petit papa noël"
							if ((count words of theToRecipient) ≥ 0) then
								if theToRecipient contains "," then
									return word 2 of theToRecipient
								else
									return word 1 of theToRecipient --> "petit"
								end if
							end if
							--end tell
						end tell
					end if
				end tell
			end tell -- window 1
		else
			tell window 1
				class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, button, button, button, toolbar, group}
				name of text fields --> {"À :", "Cc :", "Cci :", "Répondre à :", "Objet :"}
				value of text fields --> {"petit papa noël", "", "", "", ""}
				tell text field to_loc
					class of UI elements --> {}
					set theToRecipient to its value --> "petit papa noël"
					if ((count words of theToRecipient) ≥ 0) then
						if theToRecipient contains "," then
							return word 2 of theToRecipient
						else
							return word 1 of theToRecipient --> "petit"
						end if
					end if
				end tell -- text field
			end tell -- window 1
		end if
	end tell
end tell -- System Events
--------------------------------------------------------------------------------------------------

I apologizes but, giving the recognized conflict between Butler and Daylite under 10.13.6, I can’t test the way they behave together.

Now, I will try to sleep a little, then I will try to build a skeleton for a script supposed to treat the different combinations. I will post it and if you are fair enough to send feedback, maybe I will be able to build a working scheme.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 02:21:22

Hello, just for info, here are the late news about the game.

Message sent to mailbutler technical support on 2020/05/24

Thank you.

I’m not interested by Mailbutler for my own use.

I’m just trying to help an user which meet problems with the trio Mail, MailButler and Daylite.
It’s why I download your product.
At my first attempt, 3 days ago I got a version which prove to be obsolete.
I made a new attempt. This time I got version 2819 (13559)
When I run it with Mail v. 11.5 (3445.9.5) under 10.13.6 the duo works.

When I run Mail v. 11.5 (3445.9.5) with Daylite version 2020.13 the duo works flawlessy.

But when I try to run the trio, Mail crashes:

Mail_2020-05-22-151930_iMac-de-Yvan.crash
Mail_2020-05-22-173321_iMac-de-Yvan.crash
Mail_2020-05-23-122536_iMac-de-Yvan.crash
Mail_2020-05-23-122542_iMac-de-Yvan.crash
Mail_2020-05-23-122547_iMac-de-Yvan.crash
Mail_2020-05-23-122551_iMac-de-Yvan.crash
Mail_2020-05-23-122555_iMac-de-Yvan.crash
Mail_2020-05-23-122612_iMac-de-Yvan.crash
Mail_2020-05-23-122619_iMac-de-Yvan.crash
Mail_2020-05-23-123016_iMac-de-Yvan.crash
Mail_2020-05-23-123022_iMac-de-Yvan.crash
Mail_2020-05-23-181518_iMac-de-Yvan.crash
Mail_2020-05-23-182138_iMac-de-Yvan.crash
Mail_2020-05-23-182214_iMac-de-Yvan.crash
Mail_2020-05-23-182231_iMac-de-Yvan.crash
Mail_2020-05-23-182953_iMac-de-Yvan.crash
Mail_2020-05-23-183154_iMac-de-Yvan.crash
Mail_2020-05-24-101529_iMac-de-Yvan.crash
Mail_2020-05-24-175222_iMac-de-Yvan.crash
Mail_2020-05-24-190631_iMac-de-Yvan.crash

On my side I am unable to decide if the culprit is Mail, if it’s Mailbutler or if it’s Daylite.
But I am sure that at least one of them is a wrongdoer.

At this time, here, both extensions are uninstalled.

On 2020/05/25 they responded:

Hello,

Thank you for reaching out! Version 2.2.5.3 was the last update (support) we could provide for El Capitan.

2.2.5.3 can be downloaded from https://downloads.mailbutler.io/Mailbutler_2.2.5.3-10577.zip

If you have any problems with this version (it particularly does not work well with the combo of Daylite, Mailbutler and this old OS), I can only advise you to update your MacOS version at this point, I’m afraid.
Best Regards,

To which I responded:

You are funny.

It seems that you must return to school learning how to read. I never wrote about El Capitan.
As numerous other users, my machine can’t host more than 10.13.6 which is High Sierra.

Not a problem for me, as I already wrote, I have no use for your product.

I will just definitely trash such a shit.

Message sent today to Daylite editor:

Good luck to try to find a way to get rid of the confict between Mailbutler and your product under 10.13.6.

Of course, according to their ridiculous statement : (it particularly does not work well with the combo of Daylite, Mailbutler and this old OS), I didn’t tried to install their version 2.2.5.3.

If you find a way to reconcile your two apps, I’m all ears.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 27 mai 2020 16:38:33