Using AppleScript To Size A Window To 16×9 On MacOS
As part of an automation workflow I’m building around Elgato Stream Deck, I needed a way to size an application window to 16×9. This would be one component of a workflow that would allow me to launch an app, size the window, position it on the screen, and hide all the other windows with the push of a Stream Deck button.
The easy part was the Stream Deck configuration. The hard part was the AppleScript–I had never written one.
The Script
This AppleScript is crude, but it’s a start. I explain what the script is doing using inline comments, which in AppleScript are noted by the leading double-hyphens, although pound signs and (* *) delimiters for multi-line comments are also supported.
---------------------------------------------------------- -- SET VARIABLES ---------------------------------------------------------- -- theApp = name of the app MacOS will act upon set theApp to "ApplicationName" -- appWidth = how many pixels wide we'd like the window -- appHeight is calculated as a 16:9 ratio of "appWidth" -- Note that "as integer" means decimal portions of a -- calculation are truncated. set appWidth to 1600 set appHeight to appWidth / 16 * 9 as integer -- screenWidth = display pixel width -- screenHeight = Continue reading
