Monday, May 25, 2020

#1 2020-05-22 10:19:40 am

ChristophWi
Member
Registered: 2020-05-22
Posts: 2

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


Filed under: mail

Offline

 

#2 2020-05-22 11:14:46 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: My script does not work!?

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

Applescript:

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

Offline

 

#3 2020-05-22 11:29:41 am

ChristophWi
Member
Registered: 2020-05-22
Posts: 2

Re: My script does not work!?

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.

Last edited by ChristophWi (2020-05-22 11:37:53 am)

Offline

 

#4 2020-05-22 11:56:52 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: My script does not work!?

ChristophWi wrote:

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



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

I found one which behaves correctly with :

Applescript:

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.

Last edited by Yvan Koenig (2020-05-22 02:01:10 pm)

Offline

 

#5 Yesterday 03:47:18 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: My script does not work!?

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

Last edited by Yvan Koenig (Yesterday 03:51:48 am)

Offline

 

#6 Yesterday 06:10:14 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: My script does not work!?

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.

Applescript:

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

Last edited by Yvan Koenig (Yesterday 09:18:36 am)

Offline

 

#7 Yesterday 11:35:43 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: My script does not work!?

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.

Applescript:

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 :

Applescript:

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

Offline

 

#8 Yesterday 06:22:16 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: My script does not work!?

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:

Applescript:

-- 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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)