Maximize the window - Mac

Asked by Neo

Not a browser. I have desktop application. Want to maximize the window. I can find maximize image on top left corner and click on it. But, looking for a better solution with importing os or any other module.

Thanks for looking into this.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Sumit Bisht (sumitbisht1987) said :
#1

You could validate your currently selected window title first as there might be more than one window open. As sikuli is image dependent, the solution is not os independent.
However, one way of doing this could be by creating different routines and handling these on presence of specific type of image.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

There is no "importing os or any other module" available for application control on Mac with Jython.

The easiest way, to manage zooming without searching  is to use the following key sequence with the app focused:

# a function (german locale!)
def toggleZoom():
    type(Key.F2, KeyModifier.CTRL) # jump to menu bar
    type("f") # select Window menu
    type(Key.ENTER) # open
    type("z") # select Zoom
    type(Key.ENTER) # do it

# usage
toggleZoom()

You could add a short cut key to Systempreferences for all Programs (e.g. shift-cmd-m), so you could use:
type("m",KeyModifier.SHIFT+KeyModifier.CTRL)

Or you might use AppleScript via osascript via os.popen() to access the app's windows and do with them, what SystemEvents allows with the Mac GUI elements.

Revision history for this message
Neo (simamhussain) said :
#3

Super. The applescript worked for me. here is method I wrote. Is this fine, works always ..?

def maximize_myWindow():
    cmd = """osascript<<END
    tell application "System Events"
    tell process "<myApp>"
    click button 2 of window 1
    end tell
    end tell
    """
    os.system(cmd)

Revision history for this message
RaiMan (raimund-hocke) said :
#4

really well done :-)

I would add the app's name as function parameter.

... and you could add an
tell application theApp to activate

at the beginning, so you do not need an extra switchApp() or App().focus

... and you could add a feature to select a special window based on title text

... and ... and ... ;-)

Revision history for this message
Neo (simamhussain) said :
#5

got it.
However, I see one issue here. How do I validate if the window is already maximized :( ??
The code is not intelligent enough to check if window is already maximized. ;)

Any suggestions? Thanks so much for looking into this.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#6

Something like that:

def maximize_myWindow(myapp):
    h = SCREEN.h-30
    cmd = """osascript<<END
    tell application "System Events"
    tell process "%s"
    if %d > item 2 of (get size of window 1) then
    click button 2 of window 1
    endif
    end tell
    end tell
    """
    os.system( (cmd%("Safari", h) )

Revision history for this message
RaiMan (raimund-hocke) said :
#7

The value of h further depends on wether you have your dock visible or not and its height.

Revision history for this message
Neo (simamhussain) said :
#8

Thanks RaiMan, that solved my question.