Tobonaut
Tobonaut

Reputation: 2485

"defaults read com.apple.dock" as Objective C method

I try to read the plist / xml file which is behind the terminal commando:

defaults read com.apple.dock

I tried NSUserDefaults without success. Maybe you can help me. Thanks.

Upvotes: 1

Views: 1300

Answers (2)

Ethan
Ethan

Reputation: 18874

While JWWalker's answer that uses CoreFoundation APIs works fine, a more modern way is to use Foundation APIs, like so:

if let defaults = UserDefaults(suiteName: "com.apple.dock") {
  let orientation = defaults.string(forKey: "orientation")
  let autohide = defaults.bool(forKey: "autohide")
  ...
}

Upvotes: 4

JWWalker
JWWalker

Reputation: 22707

You can use CFPreferences, for example

CFStringRef orient = (CFStringRef) CFPreferencesCopyAppValue( CFSTR("orientation"), CFSTR("com.apple.dock") );
Boolean hidesIsValid = false;
Boolean hides = CFPreferencesGetAppBooleanValue( CFSTR("autohide"), CFSTR("com.apple.dock"), &hidesIsValid );

Upvotes: 3

Related Questions