I'm changing the .GlobalPreferences NSUserSubstitutions preference through the NSUserDefaults
class (through PyObjC, but that's besides the point).
This preference controls the text substitutions feature (e.g. which can substitute "©" for "(c)") of OS X.
After changing the preference, I want it to apply immediately in all running apps. When it's changed through the System Preferences, it applies immediately. How should I signal other apps to apply it immediately?
Update: Here's the project: https://github.com/ikonst/mac-tex-substitutions
Using the following code:
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(gotIt:) name:nil object:nil];
I was able to detect that the System Preferences application posts a notification named NSUserReplacementItemsEnabledChanged
when the text substitutions preferences change.
Knowing that, you can now post the adequate notification after changing the preferences to let know all open applications:
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"NSUserReplacementItemsEnabledChanged" object:self];
Keep in mind that NSUserReplacementItemsEnabledChanged
is not documented anywhere, so this behavior can change any time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With