OK, so what I ended up with was a Quick Action that takes series of screenshots of Preview. You need to do a little prep to ensure that the sidebar of thumbnail images is showing, and you may want to mess around with the size of the window, but it works for me with a folder of 7 sheet music PDFs.
Here’s how you set it up in Automator. Basically the same as the previous one, but with a Run AppleScript action instead of run Shell Script.
The AppleScript itself is this. Like most AppleScript, it’s terribly verbose for the amount of work it does. Copy this and paste it into the Run AppleScript field. Save it as a Quick Action so it appears in the right-click menu when you have a bunch of PDFs selected.
on run {input, parameters}
-- Set the Preview window size and location
set windowBounds to {100, 100, 900, 1000}
-- Get the files and the folder thay're in
tell application "Finder"
set selectedFiles to input as alias list
set theFolder to the container of (item 1 of selectedFiles) as alias
set dirPath to POSIX path of theFolder
end tell
-- loop through all the PDF files
repeat with f in selectedFiles
-- Set the various name variables
tell application "Finder"
set pdfName to name of f
set plainName to characters 1 thru -5 of pdfName as text
set jpegName to dirPath & plainName & ".jpg"
end tell
-- Open the PDF file and adjust the window size
tell application "Preview"
activate
open f
delay 0.25
set bounds of front window to windowBounds
set windowID to id of front window
end tell
-- Adjust the view
tell application "System Events"
keystroke 2 using command down
repeat 5 times
keystroke "-" using command down
delay 0.25
end repeat
keystroke 9 using command down
delay 0.5
key code 126 using command down
end tell
-- Take a screenshot and save it
set cmd to "screencapture -o -tjpg -l" & windowID & " " & quoted form of jpegName
do shell script cmd
-- Close the PDF
tell application "Preview" to close document 1
-- Make a folder and move the files into it
tell application "Finder"
set newFolder to make new folder at theFolder with properties {name:plainName}
move f to newFolder
move POSIX file jpegName as alias to newFolder
end tell
end repeat
end run
Here’s an example of the screenshots it produces:
Before you run it on a folder full of sheet music, do the following:
- Open one of your sheet music PDFs in Preview.
- Use the button in the upper left to make it show thumbnails of the pages.
- Adjust the width of the sidebar to make the thumbnails the size you like.
- Close the PDF.
With this setup, running the Quick Action should get Preview to open each PDF in turn with the thumbnails showing at the size you like. Try it out on a few PDFs and see if you get what you want.
You can change the overall size of the screenshots by messing with the windowBounds
list at the top of the script. The four numbers in the list are
- The horizontal position of the upper left corner of the window.
- The vertical position of the upper left corner of the window.
- The horizontal position of the lower right corner of the window.
- The vertical position of the lower right corner of the window.
The width of the screenshot image will be the difference between the third and first numbers; the height will be the difference between the fourth and second.
In case you haven’t run into this before, horizontal coordinates go from left to right and vertical coordinates go from top to bottom.
Unlike the earlier solution, which ran in the background, this will be both visually and aurally noisy. Preview windows will open, resize themselves, and close. You’ll hear the “camera click” sound when the screenshots are being taken. With luck, I’ve built in enough delays to have it run smoothly on your computer. As I said, it works on my 2017 iMac.
Good luck!