Le 17 avr. 2016 à 11:19, Yvan KOENIG a écrit :
[…]
Hello Axel
When running El Capitan, there is no text field in the splitter group so your script returns :
error "Erreur dans System Events : Il est impossible d’obtenir text field 1 of splitter group 1 of window 1 of application process \"Preview\". Index non valable." number -1719 from text field 1 of splitter group 1 of window 1 of application process "Preview"
Hello Yvan,
I tried my script under El Capitan, and it works there too.
Well, kind of.
In fact, I now better understand the OP’s problem: the side bar *must* be shown in Preview’s window for the text field to be accessible thru UI scripting. I didn’t notice, because I usually have the side bar visible in Preview.
So, let’s try to circumvent the bug:
tell application "Preview" to activate
delay 1
tell application "System Events"
tell application process "Preview"
tell front window
tell splitter group 1
set hadSidebar to exists scroll area 2
end tell
end tell
if not hadSidebar then
click menu item 2 of menu 1 of menu bar item 5 of menu bar 1
delay 1
end if
tell front window
tell splitter group 1
tell text field 1
set focused to true
set value to "test"
end tell
end tell
end tell
keystroke return
if not hadSidebar then
click menu item 1 of menu 1 of menu bar item 5 of menu bar 1
end if
end tell
end tell
With an additional generous delay… Of course, should they prove too invasive, those delays could be replaced with loops testing for the materialization of the expected UI elements.
Seems to be working under both Yosemite and El Capitan.
HTH,
Axel