Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take screenshot of second monitor with python on OSX

I am trying to make an ambient light system with Python. I have gotten pyscreenshot to save a screenshot correctly, but I can't figure out how to get it to screenshot my second monitor (if this is even possible).

Is there a way to take a screenshot of my second monitor in Python using pyscreenshot (or something else)? I am using OSX Yosemite if that makes any difference.

like image 255
Bruntaz Avatar asked May 04 '15 18:05

Bruntaz


People also ask

How to take a screenshot in Python?

Begin with importing the pyautogui library: Then call the .screenshot () method, which will return and Image object. And simply save it using any filename that works for you: And you should get a .png file in the same directory as your Python code. Below is an example of what my screenshot looks like:

How do I take a screenshot of only one monitor?

This means when you want to screenshot only a monitor by itself, start at 1. Once you identify the display to capture, you can then take the screenshot using mss_instance.grab: Monitor 0 (All Together):

How to take a screenshot of multiple monitors using imagegrab?

To take a screenshot of all displays, we can pass all_screens=True: from PIL import ImageGrab screenshot = ImageGrab.grab(all_screens=True) # Take a screenshot that includes all screens Please note that all_screens is currently only supported in Windows Now when you call screenshot.show (), you will see that multiple monitors are now displayed.

How do I take a screenshot using PIL?

To take a screenshot, we first need to import the ImageGrab module from PIL. After we have the ImageGrab module, we can call.grab () to take a screenshot from PIL import ImageGrab screenshot = ImageGrab.grab() # Take the screenshot On Linux, you must be using PIL 7.1.0 or higher for this to work; see release notes.


1 Answers

Use the built-in screencapture command and pass it 2 filenames. I believe it lives in /usr/sbin/screencapture so the command will look like this:

/usr/sbin/screencapture screen1.png screen2.png

I assume you know how to shell out to it using the subprocess module, along these lines

from subprocess import call
call(["/usr/sbin/screencapture", "screen1.png", "screen2.png"])
like image 151
Mark Setchell Avatar answered Oct 31 '22 18:10

Mark Setchell