MacOS: get screen of inactive application - python

I am trying to get a application screenshot of another process that is in the background, after I minimise the process. Anyway I could do this?
Similar to the question here.
But I couldn't get it to work on my Macbook, since instead of win32gui I am using Quartz, as os.commands for getting the screen process and screenshots.

There should be an app on your computer named Grab. It's in the Application/Utilities folder. Grab is a screenshot utility that gives you more control over what to include in a screenshot. You can take a screenshot of any window by selecting that option from Grab.

Related

Resize "size of text, apps and other items" using Selenium Python

I am currently using Selenium lib in Python to work on automation project. When the project was built up, it used specific "Scale and Layout" in windows 10 as provided in the image below
However, not all laptops will have this setting preset before they run this python script. While i could change the Resolution of the screen using following code
driver.set_window_size(1360,768)
however, i could not find a method, despite lot of google search, to set the size of "text, apps and other items" option to 100%.
The reason i need this specific setting as otherwise some of the elements go non-interactable as the screen UI change.
Please note that resetting zoom to 100% did not work.
PS: I am using Chrome Webdriver

How to run a python script when I click a button on webpage?

I made a simple face detection program in python. When you run the file, webcam pops up on the screen and detects your face.
The thing is, I want to run that file on a web page. Let's say I made a simple html file that has a button in it. If you click that button, I want the python script to run, so that the webcam would pop up on the screen and detect me.
I have developed server with nodejs and express before. What should I use to make that happen? Do i need to use some modules? Or is it only possible if I use Django instead?(Is this a possible option?)Thanks in advance..

How to take screenshot of background app in python 2.7 for mac

I have been trying to make a program that notifies me when a number changes on an app. I have been using ImageGrab and then pytesseract which works but I can only figure out how to take the screenshot when I can visually see the number. It would be very nice if there was a way to take an image of the app if it was minimized (not visible on the screen) so I could work on other things as it ran. I also need the picture of a certain part of that app I need to do a bounding box within the app of where the picture is taken.
This is what I am currently using which takes a certain part of the whole screen:
img = ImageGrab.grab(bbox=(1400,875,1445,905))
I think there might be a way to do it with Quartz but I could not find out how to do a region of a background app.
It is possible to take screenshots of windows that are running in the background with the screencapture api in MacOS. You can see the documentation by typing man screencapture in the terminal.
For your use case it would look something like this:
screencapture -l <windowId> -R <x,y,w,h>
As you mentioned, you can use Quartz to find the desired windowId:
from Quartz import CGWindowListCopyWindowInfo, kCGNullWindowID, kCGWindowListOptionAll
windowName = 'Desktop' # change this to the window you are looking for
def findWindowId():
windowList = CGWindowListCopyWindowInfo(
kCGWindowListOptionAll, kCGNullWindowID)
for window in windowList:
if(windowName.lower() in window.get('kCGWindowName', '').lower()):
return window['kCGWindowNumber']
return None
You can find a fully working example here
Note: From my testings, if you minimise(cmd + m) or hide(cmd + h) a window, taking a screenshot of it will only capture the moment before it was hidden. You would need to keep the window opened for it to work--but it is ok to keep it behind other windows. Tested on MacOS v10.15.7.

Ghost in Python isn't taking full resolution browser screenshots

Windows 7/Python 2.6
I am trying to take full browser screenshots and then use pillow to compare the images. I have started to use Ghost for the screenshots because i couldn't seem to get Selenium/PhantomJS to take full browser screenshots in headless mode. When i take a screenshot using Ghost the resolution of the images are like 780x8000 even thought i set the viewport size to 1920x680 (just testing resolution sizes while getting use to pillow). Sadly i can't share the screenshots but here is just is a snippet of code.
from ghost import Ghost
self.ghost = Ghost(viewport_size=(1920,680))
self.ghost.open('someurl')
self.ghost.capture_to('somedir')
After taking the screenshot the image is showing all the items in the webpage, but at the 1000px wide breakpoint for the layout.
Can someone either explain how to get the desired results of getting screenshots at 1920x"PageHeight" using either ghost or possible some other python package?
I have found the fix and it is to not set the viewport size in the constructor but using the set_viewport_size(x,y) method.
You should be able to take headless screenshots w/ selenium+phantomjs if you call
driver.set_window_size(x, y)
and then
driver.get_screenshot_as_file( "/path/to/img.png" )

Screen overlay with Python, paint over an active window with background python script

I'm writing a python script that runs in the background and takes screenshots of another application that is active. Then it analyses the screenshots and now it should overlay a certain image over the active app or the screen. I still need to be able to make mouse and keyboard inputs in the active app.
So I need a way to overlay/paint on another window or on the screen, and still keep the other window the active window so that I can make inputs.
I would prefer to do that with python in Mac OS, but if it isn't possible, other languages and even Windows (if really necessary) would also be ok.
Can anybody help me?
Thanks in advance!
http://www.michaelfogleman.com/2009/12/drawing-on-the-windows-desktop-using-python-and-wxpython/
Seems to do what you want, but is windows only, as are some other answers to similar questions here on stackoverflow

Categories

Resources