0

I want to set that by default an application I open (specifically Preview) will be opened in maximum window size. Note that I do not want it to be in full screen. I want the window to take the maximum size - leaving room for the top-bar and the dock.

4
  • 1
    What have you tried?
    – nohillside
    Jan 12 at 15:51
  • Preview (and or macOS) does not have a preference that can be set to achieve what you request. Jan 12 at 15:54
  • Are you open to install any third-party softwares using brew? If so, then you might try tiling window managers, which would allow you to open your apps in max window size by default.
    – Rakib Fiha
    Jan 12 at 16:01
  • How do you open an application (Spotlight, clicking, terminal etc)? Jan 12 at 17:25
3

As Preview (and or macOS) does not have a preference setting that always opens windows of an application in full desktop (not to be confused with full screen), here is an alternate answer that provides for a keyboard shortcut in Preview to resize the frontmost window in Preview.

This uses no third-party anything and can be done using macOS default applications and some AppleScript code without having to mess with System Integrity Protection.

Create an Automator Service/Quick Action with settings as shown in the image further below.

Add a Run AppleScript action replacing the default code with the following example AppleScript code:

tell application "Finder" to ¬
    set {missing value, missing value, ¬
        desktopWidth, desktopHeight} to ¬
        the bounds of window of desktop

tell application "System Events" to ¬
    tell application process "Finder" to ¬
        set {missing value, menubarHeight} to ¬
            the size of menu bar 1

tell application "System Events" to ¬
    tell application process "Dock" to ¬
        set {missing value, dockHeight} to ¬
            the size of list 1

tell application "Preview" to ¬
    if (exists front window) then ¬
        set bounds of front window to ¬
            {0, menubarHeight + 1, desktopWidth, ¬
                desktopHeight - dockHeight}

Assign it a keyboard shortcut in: System Preferences > Keyboard > Shortcuts > Services

I used ⌥⌘F as it is not currently assigned in Preview.


Testing in macOS Catalina, the first time I used it I had to click the OK button on the message box shown below.

Preview permissions


Automator Quick Action


Notes:

The example AppleScript code shown above assumes the Dock is always visible and additional coding is required if the Dock is hidden.

If you are one that likes to have the Dock hidden, then use the following example AppleScript code instead of the previous example AppleScript code:

tell application "Finder" to ¬
    set {missing value, missing value, ¬
        desktopWidth, desktopHeight} to ¬
        the bounds of window of desktop

tell application "System Events" to ¬
    tell application process "Finder" to ¬
        set {missing value, menubarHeight} to ¬
            the size of menu bar 1

tell application "System Events" to ¬
    tell application process "Dock" to ¬
        set {missing value, dockHeight} to ¬
            the size of list 1

tell application "System Events" to ¬
    set dockIsHidden to ¬
        autohide of dock preferences

if dockIsHidden then
    set windowHeigth to desktopHeight
else
    set windowHeigth to desktopHeight - dockHeight
end if

tell application "Preview" to ¬
    if (exists front window) then ¬
        set bounds of front window to ¬
            {0, menubarHeight + 1, ¬
                desktopWidth, windowHeigth}

If by chance you want this to act on all windows in Preview then change the tell application "Preview" command as the last command in the code to the following example AppleScript code:

tell application "Preview" to ¬
    if (exists windows) then ¬
        set bounds of windows to ¬
            {0, menubarHeight + 1, ¬
                desktopWidth, windowHeigth} 
1

Solution 1:

Here is one solution to this, which is using a tiling window manager called yabai.

Look at their git repo at: https://github.com/koekeishiya/yabai

Note: It requires some advance settings to be configured in SIP and requires yabai to be installed with scripting addition. If you do not want to mess around with System Integrity Protection, then see Solution 2 instead.

Prerequisite

  • Homebrew
  • SIP configuration

System Integrity Protection needs to be (partially) disabled for yabai to inject a scripting addition into Dock.app for controlling windows with functions that require elevated privileges. This enables control of the window server, which is the sole owner of all window connections, and enables additional features of yabai. If you are running on macOS High Sierra 10.13.6, you can reenable SIP after the scripting addition has been installed.

  • In the Mission Control preferences pane in System Preferences, the setting "Displays have separate Spaces" must be enabled.
  • In the Mission Control preferences pane in System Preferences, the setting "Automatically rearrange Spaces based on most recent use" should be disabled for commands that rely on the ordering of spaces to work reliably.

More details at: https://github.com/koekeishiya/yabai

Homebrew

Install homebrew if you do not have it already by copying and pasting the following in your terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

SIP configuration

Boot in recovery mode and execute the following in the terminal:

csrutil enable --without debug --without fs
# after executing the above reboot
reboot

Install yabai with scripting addition

Install by:

brew install koekeishiya/formulae/yabai
# install the scripting addition
sudo yabai --install-sa

# if macOS Big Sur, load the scripting addition manually; follow instructions below to automate on startup
sudo yabai --load-sa

For details see their official installation guide here

Start yabai

# start yabai
brew services start yabai

Now, when you open an app in an empty window, it will always open with maximum window size. However, if there are two apps in one window, each will take half of the window, so on and so forth. If you want one specific app to be with maximum size, I recommend using Command ⌘ + H to hide those apps, allowing your intended app to take maximum size automatically. To navigate the hidden apps use Command ⌘ + TAB

If you want to stop yabai, stop it by:

brew services stop yabai

Solution 2:

Use keyboard-centric apps like spectacle, skhd rectangle etc to resize apps by using keyboard shortcuts instead.

Spectacle (easiest): brew install --cask spectacle

rectangle (easiest): brew install --cask rectangle

skhd (works well with yabai): brew install koekeishiya/formulae/skhd && brew services start skhd

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .