Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stephancasas/236f543b0f9f6509f5fe5878de01e38a to your computer and use it in GitHub Desktop.
Save stephancasas/236f543b0f9f6509f5fe5878de01e38a to your computer and use it in GitHub Desktop.

Revisions

  1. stephancasas created this gist Oct 7, 2023.
    39 changes: 39 additions & 0 deletions sonoma-text-insertion-point-downgrade.jxa.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/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 ? '😃' : '🫤';
    }