Cropping PDFs with AppleScript

Due to Coronavirus the printing of our yearbooks was delayed, so we decided to distribute it digitally until the print version was available. There are lots of tools, like ISSUU, Uberflip, or even Google Drive that can do a decent job of displaying a PDF, password protecting it, and preventing it from being downloaded. The challenge was to get the galley proofs with crop marks, etc. into the right format. Further complicating things were that the odd/even pages had crop markets that were offset, so they had to be cropped differently.

Here is an example of a page with the dotted crop marks and the metadata on the bottom.

Fortunately Adobe Acrobat is scriptable. Normally, I tend to avoid installing Acrobat, in favor of using Preview, but its support for scripting is surprisingly good. The follow AppleScript crops odd/even pages differently and solved my problem. (based on https://macscripter.net/viewtopic.php?id=32586)

tell application "Adobe Acrobat"
activate tell active doc repeat with i from 1 to count of pages tell page i set {L, T, R, B} to media box if ((i mod 2) = 0) then set crop box to {L + 37, T - 39, R, B + 156} else set crop box to {L, T - 39, R - 37, B + 156} end if end tell end repeat end tell end tell

Virtual Graduations & End of Year Events in the time or Coronavirus: Stream Deck

In a previous post, I mentioned that I used Wirecast to do live video production of events I broadcast using Zoom. Normally, I’d like to have someone helping me, but that’s much harder when everyone is remote. Fortunately, I found the Elgato StreamDeck to help. It’s a USB hardware device with a bunch of buttons. Each button can trigger an action. Each button acts as a little screen that can be customized. There is a rich ecosystem of plugins for Strem Deck that make it work with other tools.

Here is what it looks like from a recent production:

Most of the blue buttons are clips in Wirecast and the bottom left button is the “play” button for Wirecast. The little red dot on the top left clip shows that it is live. A green dot on another clip shows that it is “next.” I really like the Wirecast plugin for Stream Deck since it gives feedback on what is playing (the red/green dots).

On the bottom right are five buttons that control Zoom (focus/ turn on/off webcam, turn on/off mic, show participants window, show chat window). They are based on the work of LostDomain and make use of Keyboard Maestro, and it’s plug-in for StreamDeck.

The black buttons are for when we went live and I muted the virtual webcam so that the active speaker became the live speaker.

What is nice is that I can control Wirecast while it is in the background and I’m managing Zoom.

Here is another picture of the StreamDeck from another production:

For this production I didn’t use the virtual webcam and instead played videos in QuickTime. The video quality seemed to be a bit better when sharing my screen rather than using a virtual webcam, and video quality was really important for this production.

The two columns of buttons on the right are mostly to control Zoom (except the bottom two). I added a shortcut to the “Share” button and “Record” (again, making use of Keyboard Maestro). The bottom right is a clock that shows the time (including seconds).

All of the other buttons are AppleScripts to control QuickTime Player and Preview. One of the challenges of using QuickTime to play videos in front of an audience (Zoom or in-person) is that they can see you futzing around opening the video and going full-screen. Using AppleScript can really minimize this, especially when triggering it from the StreamDeck.

Here is a little AppleScript to open and play fullscreen a Quicktime video (based on https://gist.github.com/biojazzard/2829190):

set unixpath to "/Users/ssimon/Desktop/PA Night Long.mp4"
set macfile to (POSIX file unixpath)
tell application "QuickTime Player"
	activate
	delay 0.5
	open file macfile
	set looping of document 1 to false
	--FullScreen
	--FullScreen
	--set presenting of document 1 to true
	--GetBounds
	present document 1
	play document 1
	
end tell

I also wanted to be able to pause the video:

tell application "QuickTime Player"
	activate
	delay 0.5
	pause document 1
end tell

And to play:

tell application "QuickTime Player"
	activate
	delay 0.5
	present document 1
	play document 1
end tell

I also wanted to close a video (QuickTime Player will open additional videos in tabs when in fullscreen):

tell application "QuickTime Player"
	activate
	close document 4
end tell

You can also open a document in Preview in fullscreen:

set unixpath to "/Users/ssimon/Desktop/roman.jpg"
set macfile to (POSIX file unixpath)

tell application "Preview"
	activate
	open file macfile
	tell application "System Events"
		keystroke "f" using {control down, command down}
	end tell
end tell

The end result is that nobody sees me moving my mouse around to control QuickTime Player or Zoom and I can rapidly play a video.

For the show, I launched the video (via a StreamDeck button / AppleScript), immediately paused it (via a StreamDeck button / AppleScript), used the Stream Deck “Share” button for Zoom to open the screen sharing window, picked the QuickTime Player window, checked “Optimize for full-screen video clip” and “Share computer sound”, and then the “Share Screen” button. Then I hit “play” (via a StreamDeck button / AppleScript). When the video was over, I stopped sharing my screen and let the speaker talk, and when he was done, I repeated the process all over for the next video.

In the future, I’ll probably change the AppleScript not to play the video and leave it paused, to simplify the process.

I haven’t had a chance to play with it, but there is a mobile version of the StreamDeck software for Android and iOS which looks like it could be a cheaper alternative to buying a StreamDeck.