如何为MacOS System Settings已有选项添加更多自定义选择?
Great question! Let’s break this down clearly—short answer: it’s possible to let users set extra small/large sidebar icons, but you can’t directly add those options to the native Appearance panel in System Settings. Here’s what you need to know:
What’s Under the Hood First
The Sidebar Icon Size options in Appearance map to a hidden system preference key: NSNavSidebarIconSize in the global user defaults. The native values are:
1= Small2= Medium3= Large
If you manually set this value to 0 (Extra Small) or 4 (Extra Large), macOS actually respects it—apps like Finder and System Settings will render the sidebar icons at those sizes. The catch? The native System Settings UI won’t show these extra options by default.
What You Can Do
1. Build a Custom System Settings Extension
Starting with macOS Ventura, Apple provides the SystemSettings framework that lets you add your own dedicated preference panel to System Settings. You can create a panel with "Extra Small" and "Extra Large" options, then behind the scenes modify the NSNavSidebarIconSize key using:
- Swift’s
UserDefaults.standard.set(_:forKey:)API, or - The terminal command:
defaults write NSGlobalDomain NSNavSidebarIconSize -int 0(for extra small)
This is the official, App Store-safe approach. The downside is your options live in a separate panel, not the native Appearance menu.
2. Apply Settings in the Background
If your app runs in the background, you can:
- Let users select the size via a menu bar icon or your app’s UI
- Write the corresponding value to the global defaults
- Prompt users to restart affected apps (like Finder) for changes to take effect (you can automate this with
killall Finder, but be mindful of interrupting the user’s workflow)
What You Can’t Do (And Why)
You cannot directly add options to the native Appearance panel in System Settings. Apple doesn’t expose any public APIs or hooks to modify existing system preference panels. Any workaround that tries to inject code or modify the system UI (like using private frameworks or app injection) violates Apple’s Developer Program Agreement, will get your app rejected from the App Store, and may break with future macOS updates.
Key Caveats
- Unsupported Preferences: The
NSNavSidebarIconSizekey is not officially documented, so Apple could change or remove it in a future macOS update, breaking your app. - Sandbox Restrictions: If your app uses App Sandbox, you’ll need to request the
com.apple.security.temporary-exception.shared-preference.read-writeentitlement to modify global defaults. - User Experience: Changing this setting requires restarting apps like Finder, which can be jarring for users—make sure to communicate this clearly.
内容的提问来源于stack exchange,提问作者Dinko Pehar

