Page turner

Update: This does not work on MacOS Big Sur. Unfortuantely SnapzProX wasn’t upgraded to a 64 Bit application and is no longer available.

I came across an online manual that we put online to read like a book — you had to turn each page by clicking on an on-screen arrow or pressing the left-arrow and right-arrow keys to navigate.

I wrote this small AppleScript to take over the duty of turning the pages.

repeat 1 times
	tell application "System Events" to key code 26 using {shift down, command down}
	activate application "Snapz Pro X" -- script pressess shift-command-f7 (my hotkey for snapz pro x)
	tell application "System Events" to key code 76 -- script presses enter to use last-used selection
	activate application "Snapz Pro X" 	
	tell application "System Events" to key code 76 -- script presses enter to capture the selected region
	activate application "Firefox"
	tell application "System Events" to key code 48 -- press tab to make the viewport active
	tell application "System Events" to key code 124 -- press right arrow to move to next page
	delay (random number from 7 to 10) -- Delay to let on-screen navigation elements disappear
end repeat

A couple of set-up notes.

  1. Before you start this script you should activate Snapz-Pro X and set the capture region for a selection-capture. Also, go into Snapz-Pro X’s settings and set a save directory and a naming convention to number your saved images
  2. Set the repeat value on the first line to equal the number of pages in the document you are trying to capture.
  3. In its current very simple form, you will need to check-in on it since it doesn’t error-handle anything. Especially captchas. Just stop the script and re-start it.

After the script is done collecting you page images, combine them together in Preview and output as a PDF. Once you have a PDF, use OCR software to make it searchable.

I created this script using advice found using the Complete List of AppleScript Key Codes by eastmanreference and the solution proposed by @daveisgeek on How do I automate a key press in AppleScript?