[Python] macos keeps asking permission while using mss.mss()

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use mss to capture a portion of my screen using the following code:

    import mss
    import cv2
    import numpy as np

    monitor_region = {
    "top": 810,
    "left": 1070,
    "width": 660,
    "height": 300
    }


    def get_frame(display_frame=False):
    with mss.mss() as sct:
    # Capture a single frame
    img = sct.grab(monitor_region)

    # Convert to NumPy array and display
    frame = np.array(img)
    # print(frame)
    # print("frame dim = ", frame.shape)

    if display_frame:
    cv2.imshow("Captured Region", frame)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


    when running this, my mac keeps prompting this: (https://i.sstatic.net/XWIlY2Rc.png) and I have to click allow for every request. Unfortunately, this isn't just a one time thing, it happens for every screenshot request I make. This is not feasible when I am making multiple requests. Hence, I am looking for a way to disable this security check.

    I have allowed terminal full access to the disk, and to screen and audio recording in my system settings. This still didnt work so I tried to use pyautogui to automatically allow this, but that does not work probably because macos thinks that this might be done due to a malware.

    I am expecting a solution to guide me to disable the above security check.

    Continue reading...

Compartilhe esta Página