I'm using different method with Citrix application as an example. Might be also usable for your case?
As I have created a macro to log me in automatically to my work environment, I wanted to be sure the Macro works always independent if I have second, third or only the main screen with me.
I'm not sure how to check, if it's already maximised and where it was suppose to be though.
You are right: A MAXIMIZED window is not a FULLSCREEN window. When a window is MAXIMIZED, then the KM Actions to manipulate the window size do not work.
How else could maximizing/un-maximizing a window be done?
Glad to help in any way I can. Double clicking the title bar will maximize a window (called zoom in the preferences pane). It does not actually make it full screen. Typically to do that you have to click the green circle icon, select the corresponding menu item, or use the hotkey that some applications have assigned by default, or assign your own hotkey either in the system preferences (keyboard pane, Shortcuts tab), or through a third party app such as KeyCue or Keyboard Maestro.
Thank you very much. So now I have learned that "Zoom" TOGGLES between maximized and un-maximized state of a Mac app window. Unfortunately, doing the Zoom action always toggles between the two states. But what I need is an "Un-Zoom" action that does not maximize the window when it is un-maximized. I.e., I would need to detect if the window is maximized and "Zoom" it only in the case it is maximized.
Here's something I whipped up real quick that should tell you if the front window is maximized or not.
In my very limited testing it works well, even on external monitors. However, I cannot guarantee it will work perfectly as I made it while in the middle of a phone call
The logic is pretty basic, it gets the front window size and position, sets them to coordinates, then gets the front screen size and sets those to coordinates, subtracts the size of the menu bar and then compares the two sets of variables to see if the window size matches the screen size. It will then tell you if it is maximized or not.
The variables are deleted at the end of the macro (these can be converted to local variables if you wish).
Try it out and see if it works for your needs.
EDIT (Wednesday, December 22, 2021 @ 15:27:38 PM):
I updated this to make use of some tokens @ccstone pointed out to me. In my limited testing it works quite well on a variety of screen resolution and configurations. @Peter_Panino while perhaps it's not necessary anymore, this updated macro will tell you if your front window is maximized or not.
I hope there's a way using AppleScript. but if not, I could imagine a complicated KM app that could find the dimensions of the dock. I've done something nearly identical before (finding docks inside macOS apps) but it took me weeks of work to implement it.
It actually looks to be quite easy to get all the dimensions of the dock using System Events. For my purposes the only thing I was interested in was the vertical position, which the below macro appears to get reliably, even when it is hidden.
To get all the dimension related info this is what I used:
tell application "System Events"
tell application process "Dock"
set listA to every attribute of list 1 --gets value of all attributes
set AXPosition to value of attribute "AXPosition" of list 1 --gets position
set AXSize to value of attribute "AXSize" of list 1 --gets size
set AXFrame to value of attribute "AXFrame" of list 1 --gets frame
@peternlewis is there a native Keyboard Maestro way to get the size/position of the dock like we can do for the menu bar using the MENUBARHEIGHT() function?
Yea I know, but for my purposes I was interested in vertical position since my dock is at the bottom. It would be quite simple for end-users to adjust this macro in case their dock is in a different location. I just haven't had time to expand on it yet haha
EDIT: A pretty simple modification to get both horizontal and vertical positions. Works whether the dock is on the left, right or at the bottom, whether it is hidden or not.
@Sleepy and @Peter_Panino I don't know if this would be useful to either of you guys but I wrote this macro to get the Dock information (like size, orientation and if it's visible or hidden) and display actual useable screen space according to that info.
This could likely be used in conjunction with the macro I posted earlier to determine if a window is maximized or not taking into consideration the Dock and not just the menu bar. I'll work on that as the day goes on.
EDIT: On another note, does anybody know how to collapse the macro image preview?
EDIT 2: Just realized this doesn’t take into account the menu bar height... I need to adjust some calculations and will update it shortly.
EDIT 3: I hate screen functions... running into issues reliably setting variables for multiple screen configurations. Pretty brain dead now so I'm gonna quit for the evening and take another look at this tomorrow.
EDIT 4: Because of difficulties in determining whether or not the menu bar is hidden, this macro does not work 100% when using more than one monitor. I'll leave it up for now, but I might not be able to figure out a way to get it to work reliably on multiple monitors or it might take me some time.