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.