snapshot of https://github.com/ActivityWatch/aw-watcher-window.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build / test on ubuntu-latest (py-3.9) (push) Failing after 2m36s
Build / typecheck (push) Successful in 1m38s
Build / test on macos-latest (py-3.9) (push) Has been cancelled
Build / test on windows-latest (py-3.9) (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
Some checks failed
Build / test on ubuntu-latest (py-3.9) (push) Failing after 2m36s
Build / typecheck (push) Successful in 1m38s
Build / test on macos-latest (py-3.9) (push) Has been cancelled
Build / test on windows-latest (py-3.9) (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
This commit is contained in:
42
aw_watcher_window/macos_permissions.py
Normal file
42
aw_watcher_window/macos_permissions.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
from multiprocessing import Process
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def background_ensure_permissions() -> None:
|
||||
permission_process = Process(target=ensure_permissions, args=(()))
|
||||
permission_process.start()
|
||||
return
|
||||
|
||||
|
||||
def ensure_permissions() -> None:
|
||||
# noreorder
|
||||
from AppKit import ( # fmt: skip
|
||||
NSURL,
|
||||
NSAlert,
|
||||
NSAlertFirstButtonReturn,
|
||||
NSWorkspace,
|
||||
)
|
||||
from ApplicationServices import AXIsProcessTrusted # fmt: skip
|
||||
|
||||
accessibility_permissions = AXIsProcessTrusted()
|
||||
if not accessibility_permissions:
|
||||
logger.info("No accessibility permissions, prompting user")
|
||||
title = "Missing accessibility permissions"
|
||||
info = "To let ActivityWatch capture window titles grant it accessibility permissions. \n If you've already given ActivityWatch accessibility permissions and are still seeing this dialog, try removing and re-adding them."
|
||||
|
||||
alert = NSAlert.new()
|
||||
alert.setMessageText_(title)
|
||||
alert.setInformativeText_(info)
|
||||
|
||||
alert.addButtonWithTitle_("Open accessibility settings")
|
||||
alert.addButtonWithTitle_("Close")
|
||||
|
||||
choice = alert.runModal()
|
||||
if choice == NSAlertFirstButtonReturn:
|
||||
NSWorkspace.sharedWorkspace().openURL_(
|
||||
NSURL.URLWithString_(
|
||||
"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user