1

I'm trying to interact with the default Mail app using Javascript for Automation (JXA). I want to click on the first email in the list so that it opens in its own window. but clicking does nothing. The solution suggested here is what I tried and it does not work.

enter image description here

My code:

var se = Application("System Events");
var mail = se.applicationProcesses.byName("Mail");

mail.windows[0]
.splitterGroups[0]
.splitterGroups[0]
.groups[0]
.scrollAreas[0]
.tables[0]
.rows[0].click()

If I remove the click() and use .select() it will select the email from the menu, but clicking on the email list item itself just returns null in the repl. I tried clicking on each of the inner uiElements but this doesn't work either.

codemon
  • 1,456
  • 1
  • 14
  • 26

1 Answers1

1

Here's an AppleScript that shows how to open a message in a new window. You should be able to readily translate that to JXA.

https://stackoverflow.com/a/390549/915019

It is better to use the app's object model than UI scripting.

JMichaelTX
  • 1,659
  • 14
  • 19
  • Thanks your link helped in opening the actual email. However for some things UI Scripting is necessary, and I still would like to understand why clicking on the selected email does nothing? There are other apps without proper object models that I would like to automate. – codemon Oct 05 '17 at 17:01
  • @Rup Because on this table, you need to double click on a row to open the message in the new window. Generally the click command works when an `ui element` contains the "**AXPress**" action (the rows of this table in the window of the **Mail** application have no actions). – jackjr300 Oct 05 '17 at 17:48