I am writing an AppleScript using Javascript (JXA) that uses Finders search bar to find files.
I want to move the focus from the search text field onto the file listing (so that arrow buttons and space for preview works).
I have tried a few things:
- Clicking somewhere else in the window (ignored for some reason).
.click()
the UI rows in the Finder hierarchy (ignored)..select()
the rows (they are selected, but greyed out as a secondary focus to the text field).- Setting
AXFocused
to false on the text field. - Setting
AXFocused
to true on the rows.
let ta = process.windows[0].toolbars.at(0).groups.at(4).textFields.at(0);
let attrs = ta.attributes();
// How to set this attribute to false?
for(const a of attrs) {
console.log(a.name());
if(a.name()==="AXFocused"){
console.log(a.properties());
a.setProperty("value", null);
a.setProperty("value", undefined);
a.setProperty("value", 0);
a.setProperty("value", "0");
a.setProperty("value", "false");
a.setProperty("value", false);
// Does not work - property is always true.
console.log(a.properties());
}
}
Can this be done? Is there a focus function that I am not aware of?
Examples:
This is how my current script opens the Finder window:
This is what I am trying to achieve (move the focus from the text area to the list):