For privacy reasons, OS X does not allow third-party applications (such as TextExpander) to log keystrokes, unless access for assistive devices is turned on. In OS X 10.8 and earlier: Go to the System Preferences and activate the Universal Access preference pane (the one with the little person in front of a blue background). I want to enable access for assistive devices programatically on 10.9. On 10.8 and lower I was using following Applescript to enable access for assistive devices: tell application 'System Events' if UI elements enabled is false then set UI elements enabled to true end if end tell. The feature called 'Enable access for assistive devices' is found in the Universal Access preference pane. It needs to be enabled in order for any GUI AppleScripts to run. I was trying to enable it from the Terminal, to insure that it was always enabled when needed. I struggled with this for a long time, and then finally found a simple solution.
Enable Access For Assistive Devices Mac Os Mojave
- Check the box next to 'Enable access for assistive devices' Enable Accessibility on Mac OS X 10.5 Leopard and 10.6 Snow Leopard. Open System Preferences Universal Access Check the box next to 'Enable access for assistive devices'.
- So Mac OS 10.9 will prompt a dialog for end user permission to enable Accessibility when application uses accessibility APIs. Additionally User has to Relaunch the application after enabling Accessibility. Can we enable access for assistive devices programmatically on 10.9 using Applescript.
Using a bash script to enable access to assistive devices is possible in Mavericks (and also Yosemite) despite the move to a per-app database. This is useful for entering keystrokes or clicking GUI buttons via a bash script.
Prior to OS X Mavericks, enabling access to assistive devices was relatively easy. Running the command
would enable it. But now each app now needs to be allowed or disallowed access.
I often used Applescript/osascript to simulate keystrokes or click GUI buttons, which was great for automating “un-scriptable” tasks on multiple computers. One particular feature I always found incredibly useful was logging a user in via the
loginwindow
by sending it a script from a remote machine. This proved useful in a lab environment when I wanted to open a specialized piece of software to make sure it worked on all of the machines.The script would simulate keystrokes and fill in the username and password fields and then press enter or click login. Unfortunately, Mavericks does not allow Applescript (or more accurately,
/usr/bin/osascript
) by default, which is what I used to accomplish this from my script. Trying to run this script returned an error:The first thing I tried was to drag
/usr/bin/osascript
into the Accessibility window of the Security & Privacy Preferences pane, which is how you can add other apps. This did not work as the command-line tool was not an .app .Enable Access For Assistive Devices Mac Mojave
Needless to say, after struggling to figure out how to enable this through a script, I finally found a way.
Each entry in the Accessibility window is actually part of a database file. Using sqlite3 , this file can be manipulated to add, remove, or modify items. To get
osascript
to work at the login window and be allowed access to assistive devices, run this command:If you are using
tccutil.py
:Or you can use
sqlite3
To remove it:
or completely wipe out every entry with:
osascript
must be some part of /System/Library/CoreServices/RemoteManagement/ARDAgent.app
, because another script I was working on triggered the prompt to allow it access.After enabling it in System Preferences and rebooting,
I was able to run the script I have used for years that enters a users credentials into the login window fields via a script sent from Apple Remote Desktop. The script is below, but I also have multiple versions of it on my Github page. Even one written in Python.
When enabling this, I also add a few other things that may come in useful:
This allows me to use things like the lock screen or the say command from the login window. In my scripts, I use it as a visual indicator that the job is done without having to log in. I can either listen for the command to complete or the lock screen to disappear.
Another Solution
Apple’s utility,
tccutil
only supports one command in Mavericks. I wrote my own version of it called tccutil.py. You can get it below, or look at the source code.This is just a little Python command line utility that can be used in scripts. I’m sure Apple will expand their utility, but for now, this is something you can use.
If you want to automate mouse clicks or keystrokes, I would suggest using UIElementInspector, or Accessibility Inspector, as it is called now (part of Xcode). This works great to find out what window, menu, or button names are called, so you can use them in your AppleScripts or bash scripts (
osascript
).![Enable Access For Assistive Devices Mac Enable Access For Assistive Devices Mac](/uploads/1/2/6/3/126352304/780030308.jpg)
If you are using Mavericks, you will have to--ironically--allow it access to accessibility by either dropping it in the list, or following the prompts when you run the app for the first time.
Adding
osascript
to the accessibility database doesn’t always mean your app or script will run without producing the error. Often, you need to add the app that is being manipulated. For example, if you had an AppleScript that clicked a menu in TextEdit, you would need to add TextEdit to the accessibility database.