Jump to content
Sign in to follow this  

How to change printer and number of printed copies

Recommended Posts


Hi All,

I am NOOB and I made an AutoIT script to automate printing a PDF file (2x) on a different printer. It works but it looks a bit clumsy. I'll show a part of the script (don't laugh plz)

Opt("WinTitleMatchMode", 2)

WinWaitActive("Adobe Reader")

; print command

Send ("!b")

Send ("r")


; when pressing 5 times the down arrow key, the appropiate printer will be selected, (Xerox Phaser 3130 PCL 6 on Ne00:) then press 5x the TAB key to go to

;the number of copies to print


sleep (500)


; press 7x TAB and hit ENTER to continue



Can somebody please help me with a more robust script. When the order of printers changes, the whole procedure fails. I hope there is a better way to change printer and number of printed copies.

Many thanks in advance!


Share this post

Link to post
Share on other sites

You could use the AutoItInfo tool to find out what the instances are of the combobox for the printer list is, and the edit for the numnber of copies. Then, instead of using tab to get to the correct control use ControlFocus. Instead of using the down arror to get to the printer, which as you say is unreliable, either Send the printer name to select it, or use ControlCommand.

Here is something very similar I did for printing files in a CAD program to pdf which might help. (The way I did it might not be the best either but it worked fine which is where I loose interest.)

;script to print all the drawings in the CAD program to pdf 
While 1
    $outPath = "C:\CAD\" & $Customer & "\pdfs\";
    $TCTitle = WinGetTitle("TurboCAD Professional")
    $drawing = _StringBetween($TCTitle, "[", ".tcw");the drawing displayed has it's file name in the title
    If Not IsArray($drawing) Then Exit;no drawings left to print?
    Send("!fp");select print
    If WinWaitActive("Print", "", 5) = 0 Then Exit
    ControlFocus("Print", "", "ComboBox1");select the printer list combo
    Send("CutePDF Writer");this is the printer I want
    Send("!1");fit on 1 page;only relevant for some printers?
    Send("{ENTER}");start printing
;ConsoleWrite("Will wait for Save As" & @CRLF)
    If WinWait("Save As", "", 5) = 0 Then Exit;something went wrong
    ControlFocus("Save As", "", "Edit1")
    Send($outPath & $drawing[0] & ".pdf");write the filename and path
    Send("{ENTER}");start it saving
    $wtext = WinGetText("Save As")
    If StringInStr($wtext, "already exists") Then
        Send("{Y");ENTER}");yes overwrite
    WinActivate("TurboCAD");back to CAD
    Send("!fc");close that file because it's printed and we'll do the next
    $count = 0
     ;check the last pdf was actually created
    While Not FileExists($outPath & $drawing[0] & ".pdf")
        $count += 1
        If $count > 20 Then
            MsgBox(262144, "Error", "Failed to create file" & _
                    $outPath & $drawing[0] & ".pdf")
            Exit;oh dear!


Oh, welcome to the AutoIt forums :)

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post

Link to post
Share on other sites

To select the printer I use the following code (where $Window holds the Title of the Acrobat Reader "Print" Window:

$RC = ControlCommand($Window,"",1139,"SelectString",$Printer)
    If @error Then
        MsgBox(4096, @ScriptName,"Printer '" & $Printer & "' is not defined")
        $RC = WinWaitActive($Window,"")
        $RC = Send("{ESC}")
    ; Rotate and center the printout
    $RC = ControlCommand($Window,"",563,"Check","")
    ; Set number of copies
    $RC = ControlSetText($Window,"",1154,$copies)
    ; Press "OK" Button
    $RC = ControlClick($Window,"",1)

Edited by water

My UDFs and Tutorials:


Active Directory (NEW 2018-10-19 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

ADO - Wiki


Share this post

Link to post
Share on other sites

I have a very simple solution to this..

I personally don't like mouse clicks and key sends, coz it can be real messy if there's any user input. and the beauty of any script is to make it run in the background, providing the user to do whatever he wants to do, and without disturbing him in any way.

Hence i suggest u use this. Works fine for me. n its quite easy to do thru autoit too, using the @comspec macro. or just running a batch file.

Edited by Manjish

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post

Link to post
Share on other sites

I also had similar automation about printing a document

Try this code:

WinActivate("Adobe Reader",'')

;============Make a loop here for multiple printer to print===========================

ControlFocus("Print","","[CLASS:ComboBox; INSTANCE:1]"); set the focus to combo box
ControlCommand("Print","","[CLASS:ComboBox; INSTANCE:1]","SelectString",'Printer Name'); select the printer name 
ControlFocus("Print","","[CLASS:Edit; INSTANCE:2]"); set the focus to Copies combo box
ControlSetText("Print","","[CLASS:Edit; INSTANCE:2]",""); clear this default value of the Copies combo box
ControlCommand("Print","","[CLASS:Edit; INSTANCE:2]",EditPaste",'5'); set to 5 copies
ControlCommand("Print","","[CLASS:Button; TEXT:OK; INSTANCE:1]",); set the focus onOK button
ControlCommand("Print","","[CLASS:Button; TEXT:OK; INSTANCE:1]","Check", ""); click the OK button to print
;============End of loop here for multiple printer to print===========================


You can used AutoIt window info and used the ControlCommand function. it's very helpful.

let me know if this doesn't work so that I could review my programs... :)

Edited by nfaustin

[font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]

Share this post

Link to post
Share on other sites

Many Thanks Y'all.

I have successfully made a script which can select printer and number of copies, without using TAB's or Arrow buttons.



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this