Can someone help with an applescript or other shortcut for "hover typing"

I would like to be able to easily enable and disable the accessibility option of "hover typing". Apple has not provided any key combination to enable/disable it.

can someone help on solving this?

thanks
srini

Hi @srinitata,

If you create a Execute Shell Script / Task Action with this shell script, it should work:

# Get the current state of Hover Typing
current_state=$(defaults read com.apple.universalaccess hoverTypingEnabled 2>/dev/null)

# Determine the new state (toggle)
if [ "$current_state" == "1" ]; then

  echo "Hover Typing is currently enabled. Disabling it..."
  defaults write com.apple.universalaccess 'hoverTypingEnabled' -bool false
else

  echo "Hover Typing is currently disabled. Enabling it..."
  defaults write com.apple.universalaccess 'hoverTypingEnabled' -bool true
fi

# Restart the universalaccessd daemon
echo "Restarting universalaccessd..."
kill $(pgrep universalaccessd)
echo "universalaccessd restarted."

Note

It takes a couple of seconds to toggle on and off, but it should work.


Paste this into BTT to create the Action automatically.

[
  {
    "BTTActionCategory" : 0,
    "BTTPredefinedActionType" : 206,
    "BTTPredefinedActionName" : "Execute Shell Script  or  Task",
    "BTTShellTaskActionScript" : "# Get the current state of Hover Typing\ncurrent_state=$(defaults read com.apple.universalaccess hoverTypingEnabled 2>\/dev\/null)\n\n# Determine the new state (toggle)\nif [ \"$current_state\" == \"1\" ]; then\n\n  echo \"Hover Typing is currently enabled. Disabling it...\"\n  defaults write com.apple.universalaccess 'hoverTypingEnabled' -bool false\nelse\n\n  echo \"Hover Typing is currently disabled. Enabling it...\"\n  defaults write com.apple.universalaccess 'hoverTypingEnabled' -bool true\nfi\n\n# Restart the universalaccessd daemon\necho \"Restarting universalaccessd...\"\nkill $(pgrep universalaccessd)\necho \"universalaccessd restarted.\"",
    "BTTShellTaskActionConfig" : "\/bin\/bash:::-c:::-:::",
    "BTTEnabled2" : 1
  }
]
1 Like

If you’re curious about how I discovered the command to toggle "Hover Typing," here’s a quick overview of my approach:

  1. Inspect the system settings: macOS stores settings in .plist (property list) files, and these can be read and modified using the defaults command. To start, I opened my terminal and ran the following command to save the current system settings into a file called before:

    defaults read > before
    
  2. Toggle Hover Typing manually: I then went to the System Settings app and enabled "Hover Typing" manually.

  3. Capture the new settings: After toggling the setting, I went back to my terminal and saved the updated system settings into another file, after:

    defaults read > after
    
  4. Compare the changes: To figure out which setting was modified, I used the diff command to compare the two files (before and after):

    diff before after
    

    This command output a lot of differences, but one relevant line stood out:

    <         hoverTypingEnabled = 0;
    ---
    >         hoverTypingEnabled = 1;
    

    This tells us that the system uses the key hoverTypingEnabled to track whether Hover Typing is enabled (1) or disabled (0).

  5. Verify and apply: With that information, I was able to query the current value of Hover Typing using:

    defaults read com.apple.universalaccess hoverTypingEnabled
    

    Then, I used the defaults write command to toggle the setting, as described in my earlier post.

  6. Restarting the necessary process: When I ran the script, I realized that the change wouldn't take effect unless I either restarted System Settings and navigated back to the Hover Typing page or killed the universalaccessd process in Activity Monitor. I found that killing the universalaccessd process was more efficient, and that’s why I added the following command to the script:

    kill $(pgrep universalaccessd)
    

    This command restarts the process and ensures the setting change is applied without needing manual intervention.


I hope this walkthrough helps! Feel free to ask if you have any questions.

1 Like

Thanks a lot!! i will try it out :pray:t4:

The actual switching doesnt get executed. it reads the status of hovertyping correctly, but actually doesnt switch status.

also i did not understand where I should paste the code mentioned in "Paste this into BTT to create the Action automatically."

I am on macos Sequoia and BTT 4.71
Thanks again for this!

@srinitata

That's strange. It's working correctly on my Mac.
Could you please share a screen recording showing it not working?

You should paste the JSON in the Action configuration section of BTT.

Hi @fortred2 - thanks a lot for the directions on video. appreciate your time helping me. I have tried exactly as per the instructions but issues still remain. I have tried to show it in my screen recording - the status of the toggle is getting recognized but the script is unable to toggle it. I am not sure if there is anything else that needs to be done.

regards
Srini

hi! I found out the issue why the script was not working. it was BTT not having full disk access. now the script works fine and is able to toggle the hover typing setting.

however, i hit another block - the named trigger is not getting executed when i use it via keyboard shortcut or trackpad gesture... HUD gets displayed so I know that the trigger is being called, but the script doesnt seem to be running... any clues on this new issue :slight_smile: