Force "Preview" app to always display files taking 50% of the screen estate - can it be done?
Currently Preview opens my A4 documents like this:
..and I want it to open them like this:
Mac mini, macOS 13.6
Currently Preview opens my A4 documents like this:
..and I want it to open them like this:
Mac mini, macOS 13.6
Here is an AppleScript that I have tested on macOS 14.3.1 and 13.6.4 that calculates 50% of the screen width, and 92% of the screen height (allowing for the Dock height). It then prompts for, and opens a PDF in Preview using the calculated new application window dimensions, and finally performs GUI scripting to zoom in to the PDF 5 times to enlarge it to the new windows size.
Tested on a M2 Mac mini Pro with LG 32UN880-B 32-inch 4K display, and a 2021 16-in MacBook Pro M1 Pro.
Copy and paste into Script Editor. Click the hammer icon to compile it, and then click Run.
(*
preview_scale50.applescript
Reference: https://discussions.apple.com/thread/255470973?sortBy=oldest_first
Dynamically calculate 50% of the current desktop size and 92% of that
height to allow for the Dock. Prompt for a PDF to open and then
scale and zoom the PDF to fill the new Preview window dimensions.
Tested: Sonoma 14.3.1, Ventura 13.6.4
VikingOSX, 2024-02-11, Apple Support Communities, No {warranty, indemnity}
*)
use scripting additions
tell application "Finder"
set {x, y, size_w, size_h} to bounds of window of desktop
end tell
set preview_w to round (0.5 * size_w) as integer
set preview_h to round (0.92 * size_h) as integer
set apdf to (choose file of type "PDF")
tell application "Preview"
activate
open apdf
set bounds of window 1 to {x, y, preview_w, preview_h}
tell application "System Events"
tell application process "Preview"
set frontmost to true
repeat 5 times
-- zoom in five times
keystroke "+" using {command down}
end repeat
end tell
end tell
end tell
return
Here is an AppleScript that I have tested on macOS 14.3.1 and 13.6.4 that calculates 50% of the screen width, and 92% of the screen height (allowing for the Dock height). It then prompts for, and opens a PDF in Preview using the calculated new application window dimensions, and finally performs GUI scripting to zoom in to the PDF 5 times to enlarge it to the new windows size.
Tested on a M2 Mac mini Pro with LG 32UN880-B 32-inch 4K display, and a 2021 16-in MacBook Pro M1 Pro.
Copy and paste into Script Editor. Click the hammer icon to compile it, and then click Run.
(*
preview_scale50.applescript
Reference: https://discussions.apple.com/thread/255470973?sortBy=oldest_first
Dynamically calculate 50% of the current desktop size and 92% of that
height to allow for the Dock. Prompt for a PDF to open and then
scale and zoom the PDF to fill the new Preview window dimensions.
Tested: Sonoma 14.3.1, Ventura 13.6.4
VikingOSX, 2024-02-11, Apple Support Communities, No {warranty, indemnity}
*)
use scripting additions
tell application "Finder"
set {x, y, size_w, size_h} to bounds of window of desktop
end tell
set preview_w to round (0.5 * size_w) as integer
set preview_h to round (0.92 * size_h) as integer
set apdf to (choose file of type "PDF")
tell application "Preview"
activate
open apdf
set bounds of window 1 to {x, y, preview_w, preview_h}
tell application "System Events"
tell application process "Preview"
set frontmost to true
repeat 5 times
-- zoom in five times
keystroke "+" using {command down}
end repeat
end tell
end tell
end tell
return
I have revised the code to accommodate PDFs and all allowable image types that Preview can handle (including camera RAW. There are updated comments about the behavior of images based on their image density in the script. So, I will only zoom in for PDFs and let the images expand as they may for the revised window width.
Here is code revision 2 of the script:
(*
preview_scale50.applescript
Reference: https://discussions.apple.com/thread/255470973?sortBy=oldest_first
Dynamically calculate 50% of the current desktop size and 92% of that
height to allow for the Dock. Prompt for a PDF to open and then
scale and zoom the PDF to fill the new Preview window dimensions.
Images (e.g. camera RAW) with sufficient density will expand to the
window width without the need for zoom in. Lower density images will
automatically do this too, but with pixelation requiring manual
zoom out (⌘-) to reduce that undesirable effect.
Revision: 2 (2024-02-12)
Tested: Sonoma 14.3.1, Ventura 13.6.4
M2 Mac mini Pro w/LG 32UN880-B, 2021 16-in MacBook Pro M1 Pro
VikingOSX, 2024-02-11, Apple Support Communities, No {warranty, indemnity}
*)
use scripting additions
property allowableContent : {"com.adobe.pdf", "public.image"}
tell application "Finder"
set {x, y, size_w, size_h} to bounds of window of desktop
end tell
set preview_w to round (0.5 * size_w) as integer
set preview_h to round (0.92 * size_h) as integer
set aFile to (choose file of type allowableContent)
tell application "Finder" to set isKind to kind of aFile
tell application "Preview"
activate
open aFile
set bounds of window 1 to {x, y, preview_w, preview_h}
tell application "System Events"
tell application process "Preview"
set frontmost to true
-- only zoom in (⌘+) for PDFs
if not (isKind contains "image") = true then
keystroke "+" using {command down}
end if
end tell
end tell
end tell
return
Preview has no settings to configure this feature, nor does it remember its last window size on reopening a subsequent PDF.
So not possible without code, and then problematic as one has no direct means to control the zoom factor of Preview to accommodate its enlargement to fit the newly calculated bounds that would represent 50% of your current screen size.
Automation would still need to communicate with the Preview application using AppleScript and the support to do what you want is simply not in Preview. One can manipulate the size of the Preview window (after it is launched) but not dynamically dial in the zoom setting to make it fill the new window size.
In subsequent testing, one does not need a repeat loop to zoom in to fill the new Preview window. A single instance of a zoom gains the right enlargement - sufficient to fill the 50% Preview screen real estate. This also eliminates the disruptive appearance of multiple zooms after the document is opened.
tell application "System Events"
tell application process "Preview"
set frontmost to true
keystroke "+" using {command down}
end tell
end tell
What about automation? You can do pretty cool stuff with it on Mac..
Wow, thank you. I'll gladly give it a go. :)
Force "Preview" app to always display files taking 50% of the screen estate - can it be done?