Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancasas/236f543b0f9f6509f5fe5878de01e38a to your computer and use it in GitHub Desktop.
Save stephancasas/236f543b0f9f6509f5fe5878de01e38a to your computer and use it in GitHub Desktop.
Disable Sonoma Text Insertion Point ("Cursor" / "Caret")
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
const kCFPrefsFeatureFlagsDir = '/Library/Preferences/FeatureFlags/Domain';
const kCFPrefsFeatureEnabledKey = 'Enabled';
const kUIKitDomainPrefsTemporaryPath = '/tmp/UIKit.plist';
const kUIKitRedesignedTextCursorKey = 'redesigned_text_cursor';
function run(_) {
const dict = $.NSMutableDictionary.new;
const enabled = $.NSMutableDictionary.new;
enabled.setValueForKey(false, kCFPrefsFeatureEnabledKey);
dict.setValueForKey(enabled, kUIKitRedesignedTextCursorKey);
const error = $();
dict.writeToURLError(
$.NSURL.fileURLWithPath(kUIKitDomainPrefsTemporaryPath),
error,
);
if (typeof error.js != 'undefined') {
return `🫤: ${error.localizedDescription}`;
}
return App.doShellScript(
[
`mkdir -p '${kCFPrefsFeatureFlagsDir}'`,
`mv '${kUIKitDomainPrefsTemporaryPath}' '${kCFPrefsFeatureFlagsDir}'`,
].join(' && '),
{
administratorPrivileges: true,
},
).length == 0 ? '😃' : '🫤';
}
@stephancasas
Copy link
Author

stephancasas commented Nov 3, 2023

@somelinguist, There are a handful, yes. I haven't any clue what they do but, using Messages as my test case, I can see the process looking for their values. My bet is on the preferences keys for what you're wanting to achieve though:

  • "AppleTISAllowCapsLockLayoutSwitching"
  • "FloatingIndicatorEnabled"
  • "TSMLanguageIndicatorEnabled"
  • "TSMTraceInputSourceSelection"

Again, I don't know what data types are expected here but, whatever they are, they're being requested of the preferences daemon at runtime. Apple likes to use bitwise operations on integer values to achieve certain stored preference values, so reversing these can be a pain in the neck if you don't know exactly what outcome you're expecting.

@somelinguist
Copy link

Thanks again for your help. Are these keys something I could set in a plist file if I i could figure out the value? If so, what domain would I need to set them in? Just UIKit?

@stephancasas
Copy link
Author

@somelinguist, the keys I listed are for use with CFPreferencesSetAppValue(_:, _:, _:) with the application ID kCFPreferencesCurrentApplication or kCFPreferencesAnyApplication.

@somelinguist
Copy link

Thanks so much for your help. That's exactly what I needed.

Disabling the inline input switcher is as simple as:

defaults write kCFPreferencesAnyApplication TSMLanguageIndicatorEnabled 0

That makes the system start using the old center screen HUD style input method switcher immediately. Any open applications will still show a popup when the input method is changed. However, once an app is restarted, it will no longer show an indicator when it's changed.

That's more than enough for me. Hopefully Apple won't change it. :)

@stephancasas
Copy link
Author

@somelinguist, superb! There are some other TSM-prefixed keys which I recall seeing polled frequently, so I'll see if I can play around with those and then make another post/Gist. Maybe it's possible to fine-tune the behavior for everyone's individual liking.

@somelinguist
Copy link

That's great!

I've added a link back to here for one of the main threads I had been discussing it in. https://discussions.apple.com/thread/255161577?answerId=259775178022#259775178022

The CapsLock indicator doesn't bother me too much. But if you find a solution for it, let me know. I had posted about the missing text cursor problem in a few threads focused on the CapsLock indicator as well, since many had used your solution.

I'd be glad to help point people to any more fine-grained solution you find.

Thanks again so much for your help! It makes my system much more useable again.

@lukeswitz
Copy link

Great work on this... the hero macOS needs right now.

@agmitron
Copy link

Thanks a lot! Works!

@MysticMedusa
Copy link

Hey this has been great for turning off horrible new cursor in Chrome, Notes and so on - life-altering, thank you and yes I am happy to buy you a coffee. But I use Apple Pages + Numbers and the thick colored cursor is still showing on those - do you have any suggestions or do you think I need to get MS Word and hope that's immune?

@stephancasas
Copy link
Author

@MysticMedusa it seems like all Catalyst applications set their own insertion point color. I say this because the new cursor service is backed by UIKit and Catalyst apps use UIKit whereas other macOS apps use AppKit. How I interpret this is that disengaging the redesigned insertion point causes AppKit apps to fallback to their classic insertion point whereas UIKit apps will always use the UIKit insertion point.

That said, there are a seemingly infinite number of undocumented preferences in macOS. As I continue to research the security exploit that led me down this rabbit hole, I'll keep an eye out for keys that might achieve the outcome you want.

@stephancasas
Copy link
Author

@MysticMedusa I posted a way to change the insertion point color here on AskDifferent. It's not exactly what you're seeking, but may help in the interim.

@MysticMedusa
Copy link

MysticMedusa commented Dec 10, 2023 via email

@MysticMedusa
Copy link

MysticMedusa commented Dec 10, 2023 via email

@WRELight
Copy link

@stephancasas Thanks for developing this. After running the script, I'm having a similar issue to the above where the .plist isn't showing up in my Library/Preferences/... I've also been having issues where in specific applications the cursor vertical line flashy bit (technical term) is not appearing in some instances. I've been trying to follow along in your comments for a fix but I'm afraid it gets beyond my day to day computer skills. Do you have any next step ideas for reverting your script to defaults in an effort to get the cursor back? I suppose I'd prefer the cursor to the annoying caps lock indicator.. Any help is appreciated, thanks so much!

@stephancasas
Copy link
Author

stephancasas commented Dec 28, 2023

@WRELight, when you're looking for the property list, make sure you're looking in the root library (/Library/Preferences), and not the user library (~/Library/Preferences).

Depending on how the developer of an application wrote their app, you may encounter unexpected behavior. Unfortunately, there's little I can do in that regard because (that I know) Feature Flags are applied at the global scope — not on a per-app basis.

If you'd like to restore the cursor behavior to its stock setting, you can run the following Terminal command:

sudo rm -rf /Library/Preferences/FeatureFlags

Cheers

@WRELight
Copy link

@stephancasas Thanks so much! It was the root library vs user library thing. I appreciate it!

@aol-nnov
Copy link

gosh! so much code for a one-liner!

sudo defaults write /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor -dict-add Enabled -bool NO and you're done!

@stephancasas
Copy link
Author

@aol-nnov I opted to keep the code instead of going the one-liner route in order to preserve the UI-based privilege escalation dialogue.

Given that a sizable number of users reading this have likely never used Terminal, I anticipated the next question being "I ran the command you shared, but it won't let me type my password."

@aol-nnov
Copy link

@stephancasas that makes sense...

Also, while fighting recent MacOS updates, ha-ha, I've found a marvellous repo with nerd-ish defaults. https://github.com/kevinSuttle/macOS-Defaults

May be, you'll find it useful too! 😉

@stephancasas
Copy link
Author

@aol-nnov Thank you! I'll take a look at this for sure! :)

@MrRod
Copy link

MrRod commented Feb 5, 2024

Loving this! Thanks so much @stephancasas !

Any ETA for the app you mentioned you would write if Apple didn't find any security issues (which they didn't according to your reddit post)? I'm happy to do any testings!

@jorjGizer
Copy link

I did the script, I have an
ls -la /Library/Preferences/FeatureFlags/Domain
total 8
drwxr-xr-x 3 root wheel 96 9 фев 17:59 .
drwxr-xr-x 3 root wheel 96 9 фев 17:39 ..
-rw-r--r-- 1 jorj_gizer wheel 272 9 фев 17:59 UIKit.plist

What should I do next? Nothing was changed

@stephancasas
Copy link
Author

@jorjGizer Did you reboot your Mac?

@jorjGizer
Copy link

jorjGizer commented Feb 9, 2024

Yes, 2 times. I have Sonoma 14.3.1

@stephancasas
Copy link
Author

@MrRod Not at the moment. I've had some pressing issues with work that needed attention. I'll update the Reddit post and sent a post on X when something's ready to be published.

@stephancasas
Copy link
Author

@jorjGizer Run cat /Library/Preferences/FeatureFlags/Domain/UIKit.plist and please paste the output here.

@jorjGizer
Copy link

Снимок экрана 2024-02-09 в 18 26 25

@MrRod
Copy link

MrRod commented Feb 9, 2024

@MrRod Not at the moment. I've had some pressing issues with work that needed attention. I'll update the Reddit post and sent a post on X when something's ready to be published.

Thank you for your answer, I'll keep an eye on both Reddit and X :)

@stephancasas
Copy link
Author

@jorjGizer That looks correct. What might be causing an issue is the file ownership. I'm not certain, but I think that root needs to be the owner for the file to take effect — such is the way that launchd handles certain property lists, too. Try changing ownership with:

sudo chown root /Library/Preferences/FeatureFlags/Domain/UIKit.plist

@jorjGizer
Copy link

I do this and now I have root owner
total 8
drwxr-xr-x 3 root wheel 96 9 фев 17:59 .
drwxr-xr-x 3 root wheel 96 9 фев 17:39 ..
-rw-r--r-- 1 root wheel 272 9 фев 17:59 UIKit.plist

I reboot my Mac, maybe I forgot smth, but I want to hide this.
Снимок экрана 2024-02-09 в 18 44 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment