Trigger kb/m control and screen recording prompts on macOS

This commit is contained in:
Dillon DuPont
2025-12-03 21:08:41 -08:00
parent 1f08e02cbb
commit 907952bff6

View File

@@ -55,6 +55,34 @@ from .base import BaseAccessibilityHandler, BaseAutomationHandler
logger = logging.getLogger(__name__)
# Trigger accessibility permissions prompt on macOS
try:
# Source - https://stackoverflow.com/a/17134
# Posted by Andreas
# Retrieved 2025-12-03, License - CC BY-SA 4.0
# Attempt to create and post a mouse event to trigger the permissions prompt
# This will cause macOS to show "Python would like to control this computer using accessibility features"
current_pos = CGEventGetLocation(CGEventCreate(None))
p = CGPoint()
p.x = current_pos.x
p.y = current_pos.y
me = CGEventCreateMouseEvent(None, kCGEventMouseMoved, p, 0)
if me:
CGEventPost(kCGHIDEventTap, me)
CFRelease(me)
except Exception as e:
logger.debug(f"Failed to trigger accessibility permissions prompt: {e}")
# Trigger screen recording prompt on macOS
try:
import pyautogui
pyautogui.screenshot()
except Exception as e:
logger.debug(f"Failed to trigger screenshot permissions prompt: {e}")
# Constants for accessibility API
kAXErrorSuccess = 0
kAXRoleAttribute = "AXRole"