How can I signal to other Cocoa applications what settings have been changed?

I am changing the .GlobalPreferences NSUserSubstitutions preference through the class NSUserDefaults(via PyObjC, but beyond the point).

This preference controls the text substitution function (for example, which can replace "©" for "(c)") OS X.

After changing the preference, I want it to be applied immediately in all running applications. When it changes through System Preferences, it is applied immediately. How can I signal to other applications to apply it immediately?

Update: Here's the project: https://github.com/ikonst/mac-tex-substitutions

+5
source share
1 answer

Using the following code:

[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(gotIt:) name:nil object:nil];

I was able to find that the System Preferences application sends a notification with a name NSUserReplacementItemsEnabledChangedwhen changing text substitution settings.

Knowing that now you can publish the corresponding notification after changing the settings to find out all open applications:

[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"NSUserReplacementItemsEnabledChanged" object:self];


Keep in mind that it is NSUserReplacementItemsEnabledChangednot documented anywhere, so this behavior can change at any time.

+2
source

All Articles