I’m trying the following to enter data in the last page ‘from to’ box in the TextEdit print window.
Trouble is, it’s proving unreliable, and sometimes enters the data into the ‘from’ box instead of the ‘to’ box.
I’ve played with the timing, but it doesn’t make any difference.
The text field is part of an unknown element, UI element 1 of UI element 5 of sheet “Print” of window “Untitled 88.rtf”, and I can’t work out how to directly address it.
Can someone guide me in the right direction please.
Regards
Santa
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
delay 6
tell window 1
repeat 4 times
keystroke tab
delay 0.5
end repeat
delay 2
keystroke MaxAttachmentPages as string
delay 0.4
end tell
tell sheet "print"
keystroke return
end tell
end tell
first open System Preferences > Keyboard & Mouse > Keyboard Shortcuts
and make sure that “Text boxes and lists only” is chosen at the bottom of the window,
then try this
property MaxAttachmentPages : "4"
activate application "TextEdit"
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
tell window 1
repeat until sheet 1 exists
delay 0.5
end repeat
keystroke tab
keystroke tab
keystroke MaxAttachmentPages
click button "Print" of UI element 4 of sheet 1
end tell
end tell
I use a very similar script to do both from and to:
-- assuming text boxes and lists only (else two more tabs)
property fromPage : "2"
property toPage : "4"
activate application "TextEdit"
tell application "System Events" to tell process "TextEdit"
keystroke "p" using {command down}
repeat until exists sheet 1 of window 1
delay 0.5
end repeat
keystroke tab & fromPage & tab & toPage
click button "Print" of UI element 4 of sheet 1 of window 1
end tell
Here’s an attempt at a version that’ll work whatever the “Keyboard Shortcuts” setting. It’s OK on my machine, but isn’t guaranteed .
set MaxAttachmentPages to 4
tell application "TextEdit" to activate
tell application "System Events"
tell process "TextEdit"
--set frontmost to true
tell sheet 1 of window 1
-- Cancel any currently open sheet.
if (it exists) then
keystroke "." using command down
repeat while (it exists)
delay 0.2
end repeat
end if
-- Open the "Print" sheet.
keystroke "p" using command down
repeat until (it exists)
delay 0.2
end repeat
-- Set the focus to the "Copies & Pages" pop up button.
set value of attribute "AXFocused" of pop up button 1 to true
if (value of attribute "AXFocused" of pop up button 1) then
-- If the pop up admits to being focused, the "Keyboard Shortcuts" tab preference is "All controls".
-- It'll take five tabs to get from the pop up to the "To:" field.
set tabs to 5
else
-- Otherwise the tab preference is "Text boxes and lists only".
-- It'll take three tabs to get from the pop up to the "to:" field.
set tabs to 3
end if
repeat tabs times
keystroke tab
end repeat
keystroke MaxAttachmentPages as string
click button "Print" of UI element 4
end tell
end tell
end tell
And thanks for that information too, Stefan. I’d just come back on line to ask about it. I’m not able to test it myself as I have a legacy printer that can only be used from OS 9!
But that negative number is the largest possible negative integer - gotta tell you something is screwed up with the labeling of that text field; but the real kicker is that the other text box has the same huge number.
This may be the reason that starting number, etc. doesn’t work either.