a bit complex task in UI scripting, maybe simple by one of you buys ;)

I’m trying to get a specific ui element located inside a window of a process by attribute.

I want to set fucos of a specific 2 test fields in mail.app

1 is the text area 1 of scroll area $VAR ← this my change if Bcc or Replay to is enable, and this is the reason of my question.

I solve this by running a loop using repeat, but it takes a few seconds for the app the complete the task (5-10 secs)

I’m trying to get the element using these syntax :


tell process "Mail"
  set thisWin to window "New Message"
  set myTo to text field 1 of scroll area of thisWin whose value of attribute "AXDescription" is "cc"

  --for a test of course
  set value of attribute "AXFocused" of myTo to true
end tell

I’ve tried a lot combinations for 2 days like:


set myTo to ui element of thisWin where value of attribute "AXDescription" is "cc"

and so on…

this is the repeat solution I’m using right know :


repeat with i from 1 to the number of UI elements of thisWin
  if text area 1 of scroll area i of thisWin exists then
    set myContent to text area 1 of scroll area i of thisWin
  end if
  if text field 1 of scroll area i of thisWin exists then
    if value of attribute "AXDescription" of text field 1 of scroll area i of thisWin = "to" then
      set myTo to text field 1 of scroll area i of thisWin
    end if
  end if
end repeat

Hi,

here two shortcuts:

set ShowBccHeader to do shell script "defaults read com.apple.mail ShowBccHeader" -- 0 or 1
set ShowReplyToHeader to do shell script "defaults read com.apple.mail ShowReplyToHeader" -- 0 or 1

activate application "Mail"
tell application "System Events"
	tell menu 5 of menu bar 1 of process "Mail"
		set ShowBccHeader to enabled of menu item 8 -- true or false
		set ShowReplyToHeader to enabled of menu item 9 -- true or false
	end tell
end tell

the first version doesn’t work if you change the status manually while Mail’s running,
but works fine directly after launching Mail

thanks for the replay , but this is not what I was asking :expressionless:

I don’t know how to “store” the object that have a specific value in his attribute (to select him)
I want to do it because the number of the item index can be changed.

meanning:

if Bcc is enabled the text area 1 of scroll area 4 is the body of the mail
if Bcc is off the ext area 1 of scroll area 5 is the body of the mail

i need to store the “To” and the “Body” object in order to first, focus in the “Body” then i switch to Left to Right via gui script, the Focus the “To” like in default

thanks!

Thanks the code is working good. but I still have the same speed problem.
the code is very fast when you run it via applescript, but after saving it into .app it takes less then before, but still takes a few secs.

why is that? I always thought apps are faster then scripts :expressionless:

thanks again!