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

Posted on Feb 11, 2024 5:36 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 11, 2024 12:11 PM

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


7 replies
Question marked as Top-ranking reply

Feb 11, 2024 12:11 PM in response to szatanica

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


Feb 12, 2024 4:25 AM in response to szatanica

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


Feb 11, 2024 7:06 AM in response to szatanica

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.

Feb 11, 2024 12:50 PM in response to VikingOSX

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




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Force "Preview" app to always display files taking 50% of the screen estate - can it be done?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.