Unminimize or Fullscreen

I use two different macros for two different functions
One to change the size of the window to fullscreen and the other to unminimize windows.
Is there a way to combine the two macros together?

I want the macro to do this:
If the window is minimized then unminimized the window
Otherwise, change the size of the window to fullscreen
and never do both.

This is the macro I use to bring back windows

Window: Bring Back.kmmacros (2.3 KB)
Window: Bring Back

It doesn't work all time. For example, if I want to bring the Notes window back this macro would bring Photo Browser instead.

And this macro either do nothing or maybe I'm using it the wrong way
I'm not sure if the word unminimize means "bring window back".

Unminimize a Window.kmmacros (1.9 KB)
Unminimize Front Window

Edit: I just found this workaround for Unminimize action

There's an If/Then/Else control flow action that uses a condition you specify to determine whether to perform one set of actions or another. Here's an example, but not one that does what you would like:

In the initial part, it determines whether the active window is fullscreen: if it is, it brings the window back to normal size; it it isn't, then it toggles between a minimised and unminimised state.

Both this macro and yours will be affected by the same problem, which you noticed appears not to respond to the Unminimize Front Window action, which is almost always impossible to do because a minimsed window will rarely ever be the front window (but it can be, which usually then gets restored out of its minimised state automatically when the application comes back into focus and it's the only window that exists).

So your objective isn't a well-defined one, because you can't reliably determine how and when a macro should know when you want a particular window to be restored when it doesn't have focus.

You could use AppleScript, which might be necessary anyway as the current KM implementation of fullscreen is merely an enlargement of the window to fill the visible space on the existing desktop, and not be a genuine fullscreen event.

Here's one way to implement what you wanted, bearing in mind what I said about minimised windows:

use application "System Events"

set frontApp to the first application process whose frontmost is true -- frontmost application process

set _W to a reference to ¬
	every window of the frontApp -- all windows

set |_W₁| to a reference to the ¬
	front window of the frontApp -- front window

set isMinimised to a reference to value of attribute "AXMinimized" of |_W₁|
set isFullscreen to a reference to value of attribute "AXFullScreen" of |_W₁|

if (the number of items of _W) is 0 then return 0 -- No windows exist for the frontApp

-- If _W isn't empty, this implies a |_W₁| must exist
if not (isFullscreen or isMinimised) then -- Enter fullscreen mode
	set the value of attribute "AXFullScreen" of |_W₁| to true
else if isFullscreen then -- Restore window from fullscreen to normal state
	set the value of attribute "AXFullScreen" of |_W₁| to false
else if isMinimised then -- Restore window from minimised state to normal state
	set the value of attribute "AXMinimized" of |_W₁| to false
end if

return 1

You can insert this into a KM macro using the Execute AppleScript action and it will do the following:

  • If the front window is in fullscreen mode, it is restored to normal state;
  • If the front window is minimised (and remains the front window), then it is restored to normal state;
  • If the front window is neither fullscreen nor minimised, it is assumed to be in a normal state and thus taken to fullscreen mode.

Unminimising can and does occur if tab-switching into the application and it has no other windows that can take the focus for itself. But, I couldn't find any other situations where the minimised window would be suitably acted upon if there were other windows or if switching back to the application by clicking on the dock icon.


Thank you, The script works perfectly.
Is there a way to choose this type of fullscreen in the script instead? To make sure it never covers the Dock & Menus Bar

Sure, that's simple enough. How did you want it implemented, i.e. under what condiions would you want the window being maximised ? Or did you want it to replace the fullscreen option entirely (in which case, the macro demonstrated in the screenshot before the AppleScript pretty much does that already, the only difference being the final action that toggles minimisation instead of strictly unminimising it, but of course you can just select the appropriate option the replace Toggle Minimize with Unminimize).

Nonetheless, the extra two lines of code for the AppleScript to be able to maximise a window are these:

set _D to a reference to scroll area 1 of process "Finder" -- the desktop

-- Maximise the front window's frame
set [|_W₁|'s position, |_W₁|'s size] to [_D's position, _D's size]

So if you still want me to implement that into the script, just let me know exactly when a window should be maximised/restored/etc., and whether/how this changes the existing conditions in place for fullscreening and unmrinimising. Also tell me what version of macOS you're running, as AppleScript can work slightly differently depending on the system version.

1 Like

It didn't work at first. I made some changes and now it's working.

Unminimize Or Fullscreen #1.kmmacros (3.4 KB)
Unminimize Or Fullscreen #1

Thank you so much @CJK.

Update #1: allow Finder to unminimize

For some reason Finder doesn't respond to unminimize so I've added a new condition to the macro.
I'm not sure if there are redundancies or not but it's working anyway.
Unminimize Or Fullscreen #2.kmmacros (3.9 KB)

Update #2: allow VLC to unminimize

I wonder how many apps I'll find that don't respond to unminimize.
If anyone knows a practical solution let us know.
Unminimize Or Fullscreen #3.kmmacros (5.2 KB)

Update #3: allow Finder to resize to fullscreen
Unminimize Or Fullscreen #4.kmmacros (8.0 KB)

Update #4: stop the remaining apps from unminimizing and resizing to fullscreen at the same time.
Unminimize Or Fullscreen #5.kmmacros (8.5 KB)

1 Like