Skip to content

Commit 82e90b2

Browse files
committed
Use AppKit to figure if we have accessbility perms and pyobjc to ask for them
1 parent 25ae699 commit 82e90b2

3 files changed

Lines changed: 102 additions & 1 deletion

File tree

‎aw_watcher_window/macos.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
from ApplicationServices import AXIsProcessTrusted
2+
from AppKit import NSAlert
13
import subprocess
24
from subprocess import PIPE
35
import os
46

57

68
def getInfo() -> str:
9+
accessibility_permissions = AXIsProcessTrusted()
10+
#accessibility_permissions = False
11+
if not accessibility_permissions:
12+
title = "Missing accessibility permissions"
13+
message = "To let ActivityWatch capture window titles grant it accessibility permissions"
14+
ok = False
15+
cancel = False
16+
alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(title, ok, 'Cancel' if cancel else None, None, message)
17+
alert.runModal()
718
cmd = ["osascript", os.path.join(os.path.dirname(os.path.realpath(__file__)), "printAppTitle.scpt")]
819
p = subprocess.run(cmd, stdout=PIPE)
920
return str(p.stdout, "utf8").strip()

‎poetry.lock‎

Lines changed: 89 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ aw-client = {git = "https://github.com/ActivityWatch/aw-client.git"}
1414
python-xlib = {version = "^0.26", platform = "linux"}
1515
pypiwin32 = {version = "223", platform = "win32"}
1616
wmi = {version = "^1.4.9", platform = "win32"}
17+
pyobjc-framework-ApplicationServices = "^6.2"
18+
pyobjc-framework-CoreText = "^6.2"
1719

1820
[tool.poetry.dev-dependencies]
1921
pytest = "^5.3.2"

0 commit comments

Comments
 (0)