Reputation:
I want to be able to check the state of Mouse Keys via Applescript, so that the script can spam the 5 key (which will trigger left mouse clicks) ONLY if sticky keys is on. This will allow the script to be turned off using the shortcut to turn off sticky keys (pressing the option key 5 times).
My code so far:
on idle
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
tell process "System Preferences"
click menu item 6 of menu 1 --pseudocode
if value of checkbox "Enable Mouse Keys" is 1 then
key code 87 --press the "5" key, triggers mouse press
end if
end tell
end tell
set rn to (random number from 0.8 to 1.0) as text
return rn
end idle
My problem is with the line click menu item 6 of menu 1
and how to access the "Mouse & Keyboard" section of the Accessibility pane. If it wasn't already obvious, I have very little experience with applescript. >_>
Upvotes: 2
Views: 744
Reputation: 76
Update to @markhunte post above for OS 10.14 Mojave (might work on earlier versions too):
set plistFile to (path to preferences from user domain) & "com.apple.universalaccess.plist" as string -- Get the Universal Access plist path of this use
tell application "System Events" to set mouseDriver to value of property list item "stickyKey" of contents of property list file plistFile -- read only the value for mouse keys
plist item name "mouseDriver" changed to "SickyKey"
Upvotes: 0
Reputation: 6932
You can avoid having to open the prefpane. By directly reading the value from the Universal Access preference file
set plistFile to (path to preferences from user domain) & "com.apple.universalaccess.plist" as string -- Get the Universal Access plist path of this use
tell application "System Events" to set mouseDriver to value of property list item "mouseDriver" of contents of property list file plistFile -- read only the value for mouse keys
This will return true or false depending if it is on or not.
One caveat with reading the plist directly is any changes done in the User interface may take about 5 seconds more or less to be written to the file.
You can read here more about property list items
Upvotes: 1