Andreas Järliden
Andreas Järliden

Reputation: 1974

Modify defaults of sandboxed application from non-sandboxed app

I have an application which I'm now sandboxing. I do automated acceptance testing using the accessibility API from a different process. Before sandboxing, the test suite used CFPreferencesSetValue and friends to set certain default values for the application.

After sandboxing, the defaults are read from ~/Library/Containers/BUNDLEID/Data/Library/Preferences but the CFPreferencesSetValue functions only writes to ~/Library/Preferences as far as I understand.

Is there a way to programmatically write preferences to the sandboxed preferences without e.g. hardcoding the location and modifying the plist directly, or using the defaults command line utility.

Upvotes: 2

Views: 1154

Answers (2)

Thomas Tempelmann
Thomas Tempelmann

Reputation: 12043

Actually, there is a better way, see the answer to my own question here: How does OS X's defaults command get access to prefs of sandboxed apps?

The trick is to use the full path to the preference file in the sandbox container, minus the ".plist" extension, as the application ID.

Upvotes: 1

Thomas Tempelmann
Thomas Tempelmann

Reputation: 12043

One solution is to add an "Application Group" to your sandboxed app, thereby allowing other apps of this group to share its preferences, see: Reading NSUserDefaults from helper app in the sandbox

Upvotes: 1

Related Questions