Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take screenshots faster on macOS?

import pyautogui
import time

def test_time():
    t1 = time.time()
    for i in range(100):
        img = pyautogui.screenshot()
    t2 = time.time()
    print(t2-t1)
test_time()

I am trying to make bot, which checks pixels and then clicks at them, but screenshots taking too much time (14.93 sec for 100 screenshots) is there any faster ways to do it?


1 Answers

Depending on the platform, you might be able to speed the call up by supplying a region keyword argument, such a the following:

im = pyautogui.screenshot(region=(20, 20, 80, 80))

On Linux, this region will be used in the underlying screenshot process (which could significantly speed up the process when only a smaller region is required), but on Windows and macOS this will not help.

You could look into more specific solutions with other libraries, including MSS, which you can read the documentation here. It has a simple API and is pretty fast.

like image 116
xavc Avatar answered Jan 24 '26 13:01

xavc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!