A very simple ask but apparently either no one has asked it before or I can't seem to find it.
There's an annoying problem that was introduced with Sequoia (or maybe Ventura) where at times I may press a certain key for just long enough for a dialog to pop up on the screen telling me the Mouse Keys have been enabled.
When that happens I have to search settings to turn it back off. What is more annoying is that certain letters on my mouse no longer work as I intend so I can't search for things easily.
I would like a macro that will immediately turn the Mouse Keys off (disable it) OR at least a macro that would allow me to assign a key combination to do the same.
Is there a Macro somewhere that I could use to do this? Can't find it in the library.
Would you accept a macro that opens the System Settings in the macOS GUI, checks visually if it's on or off, and switch accordingly. (That would be easy to write.) Or do you need it to work silently behind the scenes?
If you don't accept a GUI solution, then my approach would be to switch the settings using the macOS defaults command. Figuring out how to do that means examining the output of the "defaults read" command before and after you manually make the change. Once you have found the location in the file where the setting is saved, it's quite easy at that point to write KM macros that check or change the value of that setting. This approach involves a little more work to write, but is really easy to execute.
Of course, I can't 100% guarantee that my second approach will work, but it usually does for simple macOS settings like this one.
This suggests recent versions of macOS (I'm a few versions behind) have a built-in keyboard shortcut for activating/deactivating Mouse Keys. Such a shortcut would usually be listed in Settings > Keyboard > Shortcuts > Accessibility, where it could be enabled/disabled or set to a different shortcut.
At the least, Command-Option-F5 brings up Accessibility Shortcuts, where Mouse Keys can be deactivated. That panel can be navigated with a Keyboard Maestro macro since the panel accepts Tab for moving through items and Space Bar for enabling/disabling them.
As you can see, my CMD-OPT-F5 is configured to turn voice control on and off, but if he checks the right box, he can make it switch Mouse Keys instead.
Good catch. The key is that Mouse Keys has to be the only option selected in that section of Settings. Otherwise a panel is presented for the user to choose which Accessibility setting to enable/disable.
Hey @Airy Sorry for the delayed response. Had to step out for a bit.
So I believe the 2nd option you presented (non-GUI) would be preferable for me. I'll have to take a deeper dive into your suggestion and will likely reach back out on this post to figure how to create a Macro for it.
Regarding the accessibility shortcuts, I don't believe that will be a favorable option for me for 2 reasons.
I don't know what key or combination of keys is actually enabling the Mouse Keys but I can confirm via the screenshot, that it isn't presently enabled b/c I had to manually navigate to turn it off.
Ideally I don't wish to bring up the shortcut menu to disable the Mouse Keys and would rather I use my keyboard with assignment of the typical default shortcuts.... E.g. I'd rather this new Mouse Keys shortcut not be configured by default at all.
I don't use it and personally I wish having shortcut keys assigned to it was a decision left up to me as opposed to Apple setting it up as if to assume everyone wants it.
In the section of Settings shown in your screenshot, make it so only Mouse Keys is enabled. Once that's done, Command-Option-F5 will toggle Mouse Keys on/off.
No problem at all. I don't expect instant replies.
I see from your screenshot that you have a lot of features already turned on/off by CMD-OPT-F5. Do you actually use that entire set with CMD-OPT-F5? If not, you could set it the way I suggest and that could be your shortcut.
Nevertheless, there may be other ways to solve this. As I said, the macOS defaults command is something that usually works in cases like this. All you have to do is open a macOS window, type this:
defaults read > /tmp/defaults.1.txt
Then change the mouse keys setting. Then run this command:
defaults read > /tmp/defaults.2.txt
Then examine the difference between these two BIG files. This will tell us what we need to do. Actually, I could also run this command for you. But I'm giving you a chance to do some work.
Great. As I said, it's a BIG file(s), so you can't probably compare the files with your eyes. You will need to find a tool to spot the difference. You may need to include some context in the difference between the files, because we may need some information from that context to create a command that will flip the correct value.
There were a couple of other areas in the JSON that referenced mouseKeys but there were no differences in the values from when the feature was enabled vs disabled. Although there were other differences in other areas of the file that but they didn't specifically suggest or clue as being related to mouseKeys.
So hopefully, this particular area in the file will be adequate enough to accomplish the task.
Now we have to construct the command that will toggle this value in that file. I need a little time to do that. Hopefully you extracted enough context, but I'll let you know. P.S. Good job.
Now that you provided the changed value's name, I was able to search for that string in my own file, and I needed to scroll up higher to see which "domain" the value is stored in. The domain is com.apple.universalaccess. If I had explained the word "context" better I'm sure you could have found that yourself. I need a little more time to complete the job.
Now that I found the domain (com.apple.universalaccess) I have also found the key (axShortcutExposedFeatures) but in my past experience "keys" have always been a single value. For some reason this key is multi-line, namely:
Now in order to modify just the item we require, that will take an additional step. However I need to take a food break now, and that could take an hour or more.
Modifying the defaults file (using the write subcommand of defaults) isn't for the faint of heart. I won't advise you to save the changes yourself, but I would encourage you to think about what sort of macOS command could change the line from 1 to 0 or vice versa. Just don't try to save your changes.
You did a great job up to this point, and you might have enough info here to complete the job before I get back.
P.S. It is safe for you to try this command (in Terminal):
I have succeeded in the task of changing the defaults for MouseKeys between 0 and 1. Briefly, this will change from 1 to 0: (WARNING: DO NOT TRY TO RUN THIS UNTIL IT HAS BEEN SUCCESSFULLY TESTED AND APPROVED)
...and a second action with the 1 and 0 swapped will change the setting from 0 to 1. (My method is not as clean as using the macOS command "jq" but it should be fine.)
But as always, whenever you make a change to macOS defaults, you have to tell the relevant app to re-read the new values from the defaults. In the case of the mouseKeys setting, I'm not sure which macOS has to be restarted. I tested the usual suspect tasks (eg, SystemUIServer, Finder), and was unable to find the correct one. So I asked ChatGPT what I have to do to make this key change take effect, and it said this:
2. How to Apply the Change
Unfortunately, this particular preference is tied to Accessibility system services, and in many cases:
Logging out and back in is required.
There’s no simple killall fix for mouseKeys being enabled/disabled via this key — because:
• It’s not just a preference toggle — it affects lower-level input device handling.
• It gets loaded when user accessibility session initializes, which usually happens at login.
I don't believe ChatGPT here because the System Settings app is indeed able to make the change take effect without relogging. So maybe one of the real wizards on this site can figure this final step out.
Clearly relogging is unacceptable, but it's as close as I can get to a solution without expert assistance.
Thanks for that! I've replicated the creation of the macro per your screenshot.
But before I test it I do have 1 question.
newvalues=$(echo "$values" | sed 's/mouseKeys" = 0/")
Should it not be this? Or no?
newvalues=$(echo "$values" | sed 's/mouseKeys' = 0/")
Noting your placement of the double vs single quotes.
Let me know and I'll begin testing afterward.
Thanks again!
Oh..... and secondly, provided that this does work as expected. Is there a way to monitor a change in the file for the MouseKeys being enabled so the script will automatically execute to disable it?
Doe's Keyboard Maestro have any such feature like a file system watcher? I don't see any such option in the list of available triggers
My script was correct, with that double quote. No, you should not change it to a single quote. In fact, you changed one of the quotes at the end of my command. Don't change anything!
As I said above, it won't work until we find the correct process to restart. I don't know what that process is. I was hoping someone would tell us here, but I haven't found it yet. So there's no need for you to run any scripts yet because we still don't know what process to restart.
That sounds like a new problem, which my code doesn't address. Previously, you didn't specify that monitoring requirement. But yes, it's easy to write a KM script that polls for the setting for mouseKeys. Let's delay that new problem until after we fix your original problem.
I think you are missing an important point. It's not a file that we are changing. The defaults command in macOS is an app. You check its values by running the defaults app, not by monitoring a file. So files have nothing to do with the problem here.
Are you sure you haven't got "Press the Option key file times to toggle Mouse Keys" switched on?
Easiest way to check is to open System Settings and type "press the option key five" into the search box -- clicking on the only result will bring up the dialog you want.
I checked that option and yes that option as well as "Ignore built-in trackpad when Mouse keys is on" were both enabled. Apparently the OS enables those options as a default b/c I never knew of either option nor ever had need of them. I've disabled them both now.
As I initially said, I don't know nor ever paid any attention as to which keys triggered the Mouse Keys on. From my perspective, it just happened. So I can't definitively say that I may have pressed the option key enough times to trigger that option; but I can't imagine any instance where I would have deliberately had need to hit it 5 times either.
That said, do you believe turning these options off in addition to ensuring the Mouse Keys option is disabled will permanently eliminate the need of having a macro? For which my post was initially opened?
But if you never use the feature, turning off all the things that turn it on is much easier than finding ways to turn it off! So start there and see how you get on.