Skip to content

Commit

Permalink
Add accessibility settings link button
Browse files Browse the repository at this point in the history
  • Loading branch information
xylix committed Mar 28, 2020
1 parent 6c2c1e5 commit 890b6d6
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions aw_watcher_window/macos.py
@@ -1,20 +1,35 @@
from ApplicationServices import AXIsProcessTrusted
from AppKit import NSAlert
from AppKit import NSAlert, NSAlertFirstButtonReturn, NSButton, NSWorkspace, NSURL
import subprocess
from subprocess import PIPE
import os
import time


def getInfo() -> str:
accessibility_permissions = AXIsProcessTrusted()
#accessibility_permissions = False
#accessibility_permissions = AXIsProcessTrusted()
accessibility_permissions = False
if not accessibility_permissions:
title = "Missing accessibility permissions"
message = "To let ActivityWatch capture window titles grant it accessibility permissions"
ok = False
cancel = False
alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(title, ok, 'Cancel' if cancel else None, None, message)
alert.runModal()
info = "To let ActivityWatch capture window titles grant it accessibility permissions"

alert = NSAlert.new()
alert.setMessageText_(title)
alert.setInformativeText_(info)

ok_button = alert.addButtonWithTitle_("Ok")

accessibility_button = alert.addButtonWithTitle_("Turn on accessibility")
accessibility_button.setTitle_("Open accessibility settings")
accessibility_button.setAction_("")

alert.addButtonWithTitle_("Cancel")
choice = alert.runModal()
print(choice)
if choice == NSAlertFirstButtonReturn:
NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_("x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"))
#while True:
# time.sleep(1)
cmd = ["osascript", os.path.join(os.path.dirname(os.path.realpath(__file__)), "printAppTitle.scpt")]
p = subprocess.run(cmd, stdout=PIPE)
return str(p.stdout, "utf8").strip()
Expand Down

0 comments on commit 890b6d6

Please sign in to comment.