Le 17 avr. 2016 à 14:04, Axel Luttgens <
email@hidden> a écrit :
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
Hello Axel
Here the sidebar is rarely displayed so I had no hope to find the workaround.
I dislike predefined delays which most of the time eat too much time so I tried to get rid of them.
For the first one, it was easy because I know the tip since several months : insert an explicit set frontmost to true.
For the second one, it required more time but I got it thanks to a loop.
tell application "Preview" to activate
tell application "System Events"
tell application process "Preview"
set frontmost to true # more efficient than delay 1
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
end if
tell front window
tell splitter group 1
tell text field 1
set focused to true
set value to "abc"
end tell
end tell
end tell
keystroke return
if not hadSidebar then
repeat 5 times
delay 0.05
click menu item 1 of menu 1 of menu bar item 5 of menu bar 1
if value of attribute "AXMenuItemMarkChar" of menu item 1 of menu 1 of menu bar item 5 of menu bar 1 is not missing value then exit repeat
end repeat
end if
end tell
end tell
Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) dimanche 17 avril 2016 15:44:07