mirror of
https://github.com/trycua/computer.git
synced 2026-01-05 04:50:08 -06:00
Trigger kb/m control and screen recording prompts on macOS
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user