G’day
I’m trying to program the print box in text edit, specifically setting the page size from a variable.
The size could be near either the top or bottom of the list, which can be quite long. As well, it could be a sub-menu item.
I’ve come up with a script which, while fascinating to watch, takes forever.
Is there a simpler way, please?
set theSmallPaperSize to "A4"
tell application "TextEdit"
activate
tell application "System Events" to tell process "TextEdit"
delay 1
keystroke "p" using command down
tell window 1
set x to 0
repeat until sheet 1 exists
delay 0.1
set x to x + 1
if x = 100 then exit repeat
end repeat
set x to value of checkbox 1 of sheet 1
if x = 0 then
click checkbox 1 of sheet 1
delay 1
end if
click pop up button 1 of sheet 1
delay 0.2
try
click menu item theSmallPaperSize of menu 1 of pop up button 1 of sheet 1
on error
repeat until menu 1 of pop up button 1 of sheet 1 exists
click pop up button 1 of sheet 1
end repeat
set x to count of every menu item of menu 1 of pop up button 1 of sheet 1
repeat with y from x to 1 by -1
repeat until menu 1 of pop up button 1 of sheet 1 exists
click pop up button 1 of sheet 1
end repeat
try
set temp to name of menu item y of menu 1 of pop up button 1 of sheet 1 as text
on error
set temp to ""
end try
if temp ≠"Manage Custom Sizes." and temp ≠"" then
repeat until menu 1 of pop up button 1 of sheet 1 exists
click pop up button 1 of sheet 1
end repeat
delay 0.2
click menu item y of menu 1 of pop up button 1 of sheet 1
delay 0.2
try
if exists menu item theSmallPaperSize of menu 1 of menu item y of menu 1 of pop up button 1 of sheet 1 then
click menu item theSmallPaperSize of menu 1 of menu item y of menu 1 of pop up button 1 of sheet 1
exit repeat
else
try
click menu item 1 of menu 1 of menu item y of menu 1 of pop up button 1 of sheet 1
delay 0.2
repeat until menu 1 of pop up button 1 of sheet 1 exists
click pop up button 1 of sheet 1
end repeat
end try
end if
on error
try
click menu item (y + 1) of menu 1 of pop up button 1 of sheet 1
end try
end try
end if
end repeat
end try
end tell
end tell
end tell
Model: intel 24" iMac
Browser: Safari 525.20
Operating System: Mac OS X (10.5)