Posted 05 May 2024
I and my wife are crossword puzzle addicts. To feed our habits, I signed up for the NY Times crossword puzzle archives and downloaded the Friday, Saturday and Sunday puzzles (the Mon-Thurs puzzles were too easy) for each week between January 2015 and December 2022.
Originally I would print out a puzzle as required by opening/printing the puzzle file using Across Lite, but this got old in a hurry. So, I decided I would create a program to automagically print an entire folder’s worth of puzzles in ‘batch mode’ utilizing two-sided printing – yay! Looking around for the best/easiest way to accomplish this, I ran across an application called ‘AutoIt’, specifically created as a shell-script generator to run Windows (or Mac) applications and system functions.
It took a while to work my way through the command reference and examples, but eventually I was able to create an AutoIt shell script to do what I wanted; The script prompts the user for a directory containing Across Lite *.puz files, and offers to print them all in equal N-puzzle batches, thereby allowing the user to print a batch and then move the printed puzzles from the output tray to the input tray for a double-sided result.
This worked great, with the only downside being that the user’s PC cannot be used for anything else while the script is running, as it grabs the mouse cursor to launch Across Lite and print the current .puz file.
Here’s the script, as it stands now in May of 2024 (saved on my system as C:\Users\Frank\Documents\Personal\Crosswords\Print Pending\240504 PUZ Print Script.au3):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16 Author: G. Frank Paynter Created 09/24/22 Purpose: This script automates the printing of saved NYT Crossword puz files using Across Lite. Inputs: 1: Full path to a folder containing .puz files, i.e "C:\Users\Frank\Documents\Personal\Crosswords\Print Pending\2022" 2: (Optional) integer denoting number of files per print block. This causes the script to pause more often for paper changes. If missing, the default is 1/2 the number of files (half on one side, half on the other) Outputs: The default behavior is to print half of the .puz files and then pause to allow the user to flip the paper stack over for 2-sided printing. If the user changes the 'files per batch' parameter, then the prints will take place in smaller (or larger) batches. Notes: 05/04/2024 Tried to run this script, but discovered I no longer had the AutoIt app installed So, I installed it and then the script ran up to the point where the Across Lite app was invoked, whereupon it tried/failed to install it. I DL'd and installed Across Lite (Last update: Mar 28, 2017 v2.4.5). Saved this script file to '240504 PUZ Print Script.au3' and re-ran it. 05/05/2024: Note that all printing output goes to the DEFAULT printer, so make sure the default is the one you want. 05/05/2024: After printing the contents of a 'year' folder in the 'Pending' sub-folder, the entire 'year' folder should be moved from the 'Pending' sub-folder to the 'Printed Already' sub-folder #ce ---------------------------------------------------------------------------- #include <Debug.au3> #include <MsgBoxConstants.au3> _DebugSetup("Progress Log") ; 05/05/24 chg title ;Get the target folder name from the user Local $sPuzPath = GetTgtFolder() Local $iAnswer = MsgBox(BitOR($MB_YESNOCANCEL, $MB_SYSTEMMODAL), "puz Print Target Folder", "You chose the following folder:" & @CRLF & $sPuzPath & ". Continue?") If $iAnswer <> $IDYES Then MsgBox($MB_SYSTEMMODAL, "puz Print Target Folder", "OK. Bye!") Exit EndIf ;Search the folder for filenames with a puz extension ; Assign a Local variable the empty string which will contain the files names found. Local $sFileName = "" $hSearch = FileFindFirstFile($sPuzPath & "\*.puz") ;re-init search handle ; Check if the search was successful, if not display a message and quit If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files matched the search pattern.") Exit EndIf ;determine number of .puz files in this directory Local $iNumFiles = GetNumFiles($hSearch) _DebugOut("Found " & $iNumFiles & " puz files") Local $BatchSize = GetBatchSize() _DebugOut("GetBatchSize() Returned " & $BatchSize) Local $iNumBatches = Floor($iNumFiles/$BatchSize) _DebugOut("$iNumFiles = " & $iNumFiles & ", $BatchSize = " & $BatchSize & ", $iNumBatches = " & $iNumBatches) Local $str1,$str2 If $BatchSize = $iNumFiles Then $str1 = $iNumFiles & " files will be printed in one batch:" $str2 = "" ElseIf Mod($iNumFiles, $BatchSize) = 0 then ;check for exact multiple $str1 = $iNumFiles & " files will be printed in " & $iNumBatches & " batches of " & $BatchSize & " files" Else $str1 = $iNumFiles & " files will be printed in " & $iNumBatches & " batches of " & $BatchSize & " files" $str2 = " and one batch of " & $iNumFiles - ($BatchSize * $iNumBatches) EndIf Local $Res = MsgBox($MB_YESNOCANCEL, "Crossword Printing", $str1 & @CRLF & $str2 & @CRLF & @CRLF & "Continue?") if $Res <> $IDYES then _DebugOut("Terminating") Exit EndIf ;If we get to here, we are ready to start printing files using ShellExecute() and Sumatrapuz $hSearch = FileFindFirstFile($sPuzPath & "\*.puz") ;re-init search handle for $j = 1 to $iNumBatches PrintOneBatch($BatchSize) _DebugOut(@CRLF) ;pause for printer servicing $Res = MsgBox($MB_YESNOCANCEL,"Printer Service Required", "Batch " & $j & " of " & $iNumBatches & " printed; OK to Continue?") if $Res <> $IDYES then _DebugOut("Terminating") Exit EndIf Next PrintLastBatch() _DebugOut("All Done - Terminating") FileClose($hSearch) ;close the search handle so print loop starts over at top Func GetTgtFolder() ; Create a constant variable in Local scope of the message to display in FileSelectFolder. Local Const $sMessage = "Select a folder" ;09/22/22 Local Const $sRootFolder = "C:\Users\Frank\Documents\Personal\Crosswords\Print Pending" ; Display a FolderOpen dialog to select a folder. Local $sFileSelectFolder = FileSelectFolder($sMessage, "C:\Users\Frank\Documents\Personal\Crosswords\Print Pending") If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.") EndIf Return $sFileSelectFolder EndFunc ;==>Example Func PrintPuzzle() Opt("MouseCoordMode", 2) ;set mouse coord rel to active win client area ;~ MouseMove(0,0) ;~ Sleep(100) MouseMove(125,25) MouseClick("main") ;click on 'Print' icon Sleep(500) MouseMove(125,50) ;~ Sleep(500) MouseClick("main") ;click on 'puzzle' sub-menu item- c/o 09/14/16 for debug Sleep(500) EndFunc Func GetNumFiles($hSearch) ;determine number of .PUZ file in this directory Local $iNumFiles = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ; Display the file name. ; _DebugOut("Found " & $sFileName) $iNumFiles = $iNumFiles + 1 WEnd FileClose($hSearch) Return $iNumFiles EndFunc Func PrintOneBatch($numfiles) _DebugOut("PrintOneBatch(" & $numfiles & ")") For $i = 1 to $numfiles ;print one file $sFileName = FileFindNextFile($hSearch) _DebugOut($j & ", " & $i & ": Printing File " & $sFileName) ShellExecute($sPuzPath & "\" & $sFileName);open Across Lite with selected file Sleep(500) PrintPuzzle() ;click on Print --> Puzzle sleep(1000) Send("!{F4}") ;close Across Lite Sleep(1000) ;short pause Sleep(1000) ;short pause Next EndFunc Func GetBatchSize() $BatchSize = GetBatchInput() _DebugOut("Just after 1st GetBatchInput(): $BatchSize = " & $BatchSize) while ( $BatchSize = 0 OR $BatchSize > $iNumFiles) MsgBox($MB_SYSTEMMODAL, "Error", "Number of files = " & $iNumFiles & ", Batch Size = " & $BatchSize & @CRLF & "Batch size must be > 0 AND <= number of files - try again!") $BatchSize = GetBatchInput() _DebugOut("Bottom of while() loop: $BatchSize = " & $BatchSize) WEnd Return $BatchSize EndFunc Func GetBatchInput() Local $BatchSize = Floor($iNumFiles/2) If $BatchSize = 0 then $BatchSize = 1 EndIf ;~ Local $sText = InputBox("puz Printer", "Found " & $iNumFiles & " puz files. Please enter the batch size", Floor($iNumFiles/2)) Local $sText = InputBox("puz Printer", "Found " & $iNumFiles & " puz files. Please enter the batch size", $BatchSize) ;~ Local $BatchSize = 0; If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "Error", "Exiting Program") Exit Endif _DebugOut("$sText = " & $sText) if StringIsInt($sText) Then $BatchSize = Int($sText) Else MsgBox($MB_SYSTEMMODAL, "Error", "Couldn't convert " & $sText & " to an integer. Exiting program") Exit EndIf _DebugOut("$iNumFiles = " & $iNumFiles & ", $BatchSize = " & $BatchSize) return $BatchSize EndFunc Func PrintLastBatch() ;Purpose: print any remaining files $i = 1 _DebugOut("Last batch: Printing " & $iNumFiles - ($iNumBatches * $BatchSize)) While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop _DebugOut($j & ", " & $i & ": Printing File " & $sFileName); Display the file name. $i = $i + 1 ShellExecute($sPuzPath & "\" & $sFileName);open Across Lite with selected file Sleep(500) PrintPuzzle() ;click on Print --> Puzzle sleep(1000) Send("!{F4}") ;close Across Lite Sleep(1000) ;short pause WEnd EndFunc |
And here is the output log for printing the contents of the ‘C:\Users\Frank\Documents\Personal\Crosswords\Print Pending\2015’ folder containing 156 puzzle files, printed in four batches of 39 files each:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
Found 156 puz files $sText = 39 $iNumFiles = 156, $BatchSize = 39 Just after 1st GetBatchInput(): $BatchSize = 39 GetBatchSize() Returned 39 $iNumFiles = 156, $BatchSize = 39, $iNumBatches = 4 PrintOneBatch(39) 1, 1: Printing File Apr0315.puz 1, 2: Printing File Apr0415.puz 1, 3: Printing File Apr0515.puz 1, 4: Printing File Apr1015.puz 1, 5: Printing File Apr1115.puz 1, 6: Printing File Apr1215.puz 1, 7: Printing File Apr1715.puz 1, 8: Printing File Apr1815.puz 1, 9: Printing File Apr1915.puz 1, 10: Printing File Apr2415.puz 1, 11: Printing File Apr2515.puz 1, 12: Printing File Apr2615.puz 1, 13: Printing File Aug0115.puz 1, 14: Printing File Aug0215.puz 1, 15: Printing File Aug0715.puz 1, 16: Printing File Aug0815.puz 1, 17: Printing File Aug0915.puz 1, 18: Printing File Aug1415.puz 1, 19: Printing File Aug1515.puz 1, 20: Printing File Aug1615.puz 1, 21: Printing File Aug2115.puz 1, 22: Printing File Aug2215.puz 1, 23: Printing File Aug2315.puz 1, 24: Printing File Aug2815.puz 1, 25: Printing File Aug2915.puz 1, 26: Printing File Aug3015.puz 1, 27: Printing File Dec0415.puz 1, 28: Printing File Dec0515.puz 1, 29: Printing File Dec0615.puz 1, 30: Printing File Dec1115.puz 1, 31: Printing File Dec1215.puz 1, 32: Printing File Dec1315.puz 1, 33: Printing File Dec1815.puz 1, 34: Printing File Dec1915.puz 1, 35: Printing File Dec2015.puz 1, 36: Printing File Dec2515.puz 1, 37: Printing File Dec2615.puz 1, 38: Printing File Dec2715.puz 1, 39: Printing File Feb0115.puz PrintOneBatch(39) 2, 1: Printing File Feb0615.puz 2, 2: Printing File Feb0715.puz 2, 3: Printing File Feb0815.puz 2, 4: Printing File Feb1315.puz 2, 5: Printing File Feb1515.puz 2, 6: Printing File Feb2015.puz 2, 7: Printing File Feb2115.puz 2, 8: Printing File Feb2215.puz 2, 9: Printing File Feb2715.puz 2, 10: Printing File Feb2815.puz 2, 11: Printing File Jan0215.puz 2, 12: Printing File Jan0315.puz 2, 13: Printing File Jan0415.puz 2, 14: Printing File Jan0915.puz 2, 15: Printing File Jan1015.puz 2, 16: Printing File Jan1115.puz 2, 17: Printing File Jan1615.puz 2, 18: Printing File Jan1715.puz 2, 19: Printing File Jan1815.puz 2, 20: Printing File Jan2315.puz 2, 21: Printing File Jan2415.puz 2, 22: Printing File Jan2515.puz 2, 23: Printing File Jan3015.puz 2, 24: Printing File Jan3115.puz 2, 25: Printing File Jul0315.puz 2, 26: Printing File Jul0415.puz 2, 27: Printing File Jul0515.puz 2, 28: Printing File Jul1015.puz 2, 29: Printing File Jul1115.puz 2, 30: Printing File Jul1215.puz 2, 31: Printing File Jul1715.puz 2, 32: Printing File Jul1815.puz 2, 33: Printing File Jul1915.puz 2, 34: Printing File Jul2415.puz 2, 35: Printing File Jul2515.puz 2, 36: Printing File Jul2615.puz 2, 37: Printing File Jul3015.puz 2, 38: Printing File Jul3115.puz 2, 39: Printing File Jun0515.puz PrintOneBatch(39) 3, 1: Printing File Jun0615.puz 3, 2: Printing File Jun0715.puz 3, 3: Printing File Jun1215.puz 3, 4: Printing File Jun1315.puz 3, 5: Printing File Jun1415.puz 3, 6: Printing File Jun1915.puz 3, 7: Printing File Jun2015.puz 3, 8: Printing File Jun2115.puz 3, 9: Printing File Jun2615.puz 3, 10: Printing File Jun2715.puz 3, 11: Printing File Jun2815.puz 3, 12: Printing File Mar0115.puz 3, 13: Printing File Mar0615.puz 3, 14: Printing File Mar0715.puz 3, 15: Printing File Mar0815.puz 3, 16: Printing File Mar1315.puz 3, 17: Printing File Mar1415.puz 3, 18: Printing File Mar1515.puz 3, 19: Printing File Mar2015.puz 3, 20: Printing File Mar2115.puz 3, 21: Printing File Mar2215.puz 3, 22: Printing File Mar2715.puz 3, 23: Printing File Mar2815.puz 3, 24: Printing File Mar2915.puz 3, 25: Printing File May0115.puz 3, 26: Printing File May0215.puz 3, 27: Printing File May0315.puz 3, 28: Printing File May0815.puz 3, 29: Printing File May0915.puz 3, 30: Printing File May1015.puz 3, 31: Printing File May1515.puz 3, 32: Printing File May1615.puz 3, 33: Printing File May1715.puz 3, 34: Printing File May2215.puz 3, 35: Printing File May2315.puz 3, 36: Printing File May2415.puz 3, 37: Printing File May2915.puz 3, 38: Printing File May3015.puz 3, 39: Printing File May3115.puz PrintOneBatch(39) 4, 1: Printing File Nov0115.puz 4, 2: Printing File Nov0615.puz 4, 3: Printing File Nov0715.puz 4, 4: Printing File Nov0815.puz 4, 5: Printing File Nov1315.puz 4, 6: Printing File Nov1415.puz 4, 7: Printing File Nov1515.puz 4, 8: Printing File Nov2015.puz 4, 9: Printing File Nov2115.puz 4, 10: Printing File Nov2215.puz 4, 11: Printing File Nov2715.puz 4, 12: Printing File Nov2815.puz 4, 13: Printing File Nov2915.puz 4, 14: Printing File Oct0215.puz 4, 15: Printing File Oct0315.puz 4, 16: Printing File Oct0415.puz 4, 17: Printing File Oct0915.puz 4, 18: Printing File Oct1015.puz 4, 19: Printing File Oct1115.puz 4, 20: Printing File Oct1615.puz 4, 21: Printing File Oct1715.puz 4, 22: Printing File Oct1815.puz 4, 23: Printing File Oct2315.puz 4, 24: Printing File Oct2415.puz 4, 25: Printing File Oct2515.puz 4, 26: Printing File Oct3015.puz 4, 27: Printing File Oct3115.puz 4, 28: Printing File Sep0415.puz 4, 29: Printing File Sep0515.puz 4, 30: Printing File Sep0615.puz 4, 31: Printing File Sep1115.puz 4, 32: Printing File Sep1215.puz 4, 33: Printing File Sep1315.puz 4, 34: Printing File Sep1815.puz 4, 35: Printing File Sep1915.puz 4, 36: Printing File Sep2015.puz 4, 37: Printing File Sep2515.puz 4, 38: Printing File Sep2615.puz 4, 39: Printing File Sep2715.puz Last batch: Printing 0 All Done - Terminating >>>>>> Please close the "Report Log Window" to exit <<<<<<< |