Thanks to Macscripter member Budgie, I’ve got a routine to automatically print emails, but sometimes the emails run to 40-100 pages, due to client errors.
The script uses GUI interfacing to press the P and return buttons, but is there any way to limit the pages from 1 to 4 in the print dialog?
Regards
Santa
Model: G5 1.8 GHz
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Failing that, can I set the following to page 1 and page 4 somehow?
starting page (integer) : the first page of the document to be printed
ending page (integer) : the last page of the document to be printed
From the Printer Setup Dictionary…
print settings‚n
properties
copies (integer) : the number of copies of a document to be printed
collating (boolean) : Should printed copies be collated?
starting page (integer) : the first page of the document to be printed
ending page (integer) : the last page of the document to be printed
pages across (integer) : number of logical pages laid across a physical page
pages down (integer) : number of logical pages laid out down a physical page
error handling (standard/detailed) : how errors are handled
fax number (string) : for fax number
target printer (string) : for target printer
At the moment, my script looks like this…
tell application WhatToPrintpdfWith
try
activate
open file (pathToDesktopTemp & TheName as text)
delay 2
tell application "Printer Setup Utility"
copy current printer to CurrentPrinter
set current printer to printer ThePrintingPrinter
end tell
tell application "System Events" to tell process WhatToPrintpdfWith
keystroke "p" using command down
delay 0.2
tell window "print"
delay 0.2
keystroke return
end tell
if WhatToPrintpdfWith is in {"Preview", "Adobe Reader", "Adobe Acrobat Professional", "Adobe Illustrator CS3"} then keystroke "w" using command down
end tell
tell application "Finder"
move file (pathToDesktopTemp & TheName as text) to trash
end tell
on error TheError number errNum
my MoveToUnrecognizedItems(TheName, TheSuffix)
end try
end tell
These two different lines, amongst a lot of other things, doesn’t work.
What am I doing wrong please.
tell application "TextEdit"
try
activate
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
delay 0.2
tell window "print"
delay 0.2
keystroke return
end tell
tell application "Printer Setup Utility"
using terms from application "Printer Setup Utility"
set the print settings's starting page to 1
set the ending page of print settings to 4
end using terms from
end tell
end tell
on error TheError number errNum
display dialog TheError
end try
end tell
scripting TextEdit is a mess sometimes, because some basic command don’t work properly,
for example
print document 1 without print dialog
displays always the print dialog.
So, what’s about doing the whole thing with GUI scripting
set startpage to "1"
set endpage to "4"
tell application "TextEdit"
try
activate
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
tell window 1
repeat until exists sheet 1
delay 0.1
end repeat
keystroke tab
keystroke startpage
keystroke tab
keystroke endpage
click button 2 of UI element 4 of sheet 1
end tell
end tell
on error TheError number errNum
display dialog TheError
end try
end tell
I had to modify your script slightly, so here’s my finished script.
set startpage to "1"
set endpage to "4"
tell application WhatToPrintpdfWith
try
activate
open file (pathToDesktopTemp & TheName as text)
delay 2
tell application "System Events" to tell process WhatToPrintpdfWith
keystroke "p" using command down
tell window 1
repeat until exists sheet 1
delay 0.1
end repeat
keystroke tab
keystroke tab
keystroke tab
keystroke startpage
keystroke tab
keystroke endpage
delay 5
click button 2 of UI element 4 of sheet 1
end tell
if WhatToPrintpdfWith is in {"Preview", "Adobe Reader", "Adobe Acrobat Professional", "Adobe Illustrator CS3"} then keystroke "w" using command down
if WhatToPrintpdfWith is in {"GraphicConverter"} then keystroke "w" using command down and option down
end tell
tell application "Finder"
move file (pathToDesktopTemp & TheName as text) to trash
end tell
on error TheError number errNum
my MoveToUnrecognizedItems(TheName, TheSuffix)
end try
end tell
My script uses various Applications to open a whole range of email attachments, and not only that, but automatically sends them to a range of printers (any nominated one of 6).
Of ccourse, what I’d forgotten was that each App has it’s own printer dialog box, doesn’t it. So the GUI way is no good, apart from the default keystroke P using command down, and keystroke return.
I really need to know if it’s possible to limit the sheets via Printer Setup Utility.
I’ve tried, but can’t grasp the required syntax to both address Printer Setup Utility, or set it.
Here’s what I tried, but I get a null string.
tell application "TextEdit"
try
activate
tell application "Printer Setup Utility"
set CurrentPrinter to current printer
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
delay 0.2
tell window "print"
delay 0.2
keystroke return
end tell
end tell
delay 6
using terms from application "Printer Setup Utility"
copy names of CurrentPrinter's jobs to CurrentPrinterjobs -- gives null string
beep 2
--display dialog CurrentPrinterjobs as text
set the print settings's starting page to 1
set the ending page of print settings to 4
end using terms from
end tell
on error TheError number errNum
display dialog TheError
end try
end tell
No, it didn’t work ,but I didn’t know the correct syntax.
While I’m here, the following seems to copy something to the varable ‘CurrentPrinterjobs’, but it generates an error after the two beeps.
Anybody know what’s going on?
tell application "TextEdit"
try
activate
tell application "Printer Setup Utility"
set CurrentPrinter to current printer
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
delay 0.2
tell window "print"
delay 0.2
keystroke return
end tell
end tell
tell application "Printer Setup Utility"
using terms from application "Printer Setup Utility"
copy names of job items of printer CurrentPrinter to CurrentPrinterjobs
beep 2
(display dialog item 1 of CurrentPrinterjobs) as text
set the print settings's starting page to 1
set the ending page of print settings to 4
end using terms from
end tell
end tell
on error TheError number errNum
display dialog TheError
end try
end tell
copy names of job items of printer CurrentPrinter to CurrentPrinterjobs
are two mistakes:
¢ The expression job items doesn’t exist
¢ The variable CurrentPrinter contains the reference to the current printer, so omit the keyword printer
Some other notes:
¢ If you have a tell block with an application specified by a literal string, using terms from is useless.
¢ print settings is a class which belongs to the print command of Standard Suite, using it without print doesn’t work
Here you script a bit cleaned up but not working properly anyway
try
activate application "TextEdit"
tell application "System Events" to tell process "TextEdit"
keystroke "p" using command down
delay 0.2
tell window "print"
delay 0.2
keystroke return
end tell
end tell
tell application "Printer Setup Utility"
set CurrentPrinter to current printer
set CurrentPrinterjobs to name of jobs of CurrentPrinter
-- beep 2
-- (display dialog item 1 of CurrentPrinterjobs) as text
set the print settings's starting page to 1 -- causes an error
set the ending page of print settings to 4
end tell
on error TheError number errNum
display dialog TheError
end try
PS: The GUI scripting routine above is working (at least for TextEdit). Why don’t you use this?
I can’t use the text edit routine on the other programs, such as Adobe Acrobat, that are used to open and print different attachments.
There’s a long list of programs to open attachments with, depending on the quality of the desired printout.
I can use the GUI method for textedit, but badly need a generic method of limiting the number of pages printed.
The best way would be to tell the Printer Setup Utility to only print pages 1 to 4, but it’s beyond my limited skills (well, lets be honest, no darn skills)
As the printer setup dictionary doesn’t list the commands as r/o, I assumed they could be changed.
The print dialog for Adobe Acrobat cant use tabs to set the number of pages by the look of it, so it looks like we print 40-100 pages for nothing on the odd occasion.