'Get screenshot of hidden window Python Mac OS

I'm trying to take a screenshot of a background window on Mac OS using python. I can currently only get a screenshot of visible screens.

x1,y1,width,height =pygetwindow.getWindowGeometry('Google Chrome ')
x2=x1+width
y2=y1+height

im = pyautogui.screenshot(path)
im =im.crop((x1,y1,x2,y2))
im.save(path)
im.show()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source