Need a way to maintain a preference for my app, that only Administrators can modify but all users can read.

[Mac OS]
Hi, I am looking for a way to maintain a preference for my app with below requirements:

  • The preference should be editable only by an administrator ( or an user of admin group)
  • everyone should be able to read (only) the preference, so that my app can fetch it during app launch for all users

Q) Is it possible to make a certain key with above restrictions in a .plist file?
Q) Is there any better way to achieve the same on mac os.

Is your app being deployed to a managed environment? If so, managed app configuration would be a great option.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

it was not intended to be deployed in a managed environment.

Hmmm. You tagged your question with Automatic Assessment Configuration and Device Management, both of which are common MDM indicators.

The preference should be editable only by an administrator (or an user of admin group)

And this confused me two. In an unmanaged environment, an administration is a member of the admin group; there’s no “or” involved.

So, lemme get this straight:

  1. You have an unmanaged Mac.

  2. An admin logs in.

  3. They run your app and set preferences.

  4. They log out.

  5. A non-admin logs in.

  6. They can read, but not modify, these preferences.

Is that the kinda workflow you’re looking for?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

You can do this with CFPreferences, specifying kCFPreferencesAnyUser. Historically it was possible to use this to set a pref as an admin user without authenticating but that no longer works because we’ve been tightening up file system permissions. However, you seem to be happy with a command-line interface and so it’s easy to authenticate the set side using sudo.

Here’s some code snippets:

// to get 

let greetingWithDate = "Hello Cruel World! \(Date())"
CFPreferencesSetValue(
    "greetingWithDate" as NSString,
    greetingWithDate as NSString,
    "com.example.apple-samplecode.Test700292" as NSString,
    kCFPreferencesAnyUser,
    kCFPreferencesCurrentHost
)
print("did set `greetingWithDate` in `com.example.apple-samplecode.Test700292` to '\(greetingWithDate)'")

// to get 

let propQ = CFPreferencesCopyValue(
    "greetingWithDate" as NSString,
    "com.example.apple-samplecode.Test700292" as NSString,
    kCFPreferencesAnyUser,
    kCFPreferencesCurrentHost
)
guard let prop = propQ else {
    print("no property")
    … bail …
}
guard let str = (prop as? String) as String? else {
    print("wrong type")
    … bail …
}
print("did get `greetingWithDate` in `com.example.apple-samplecode.Test700292` as '\(str)'")

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Need a way to maintain a preference for my app, that only Administrators can modify but all users can read.
 
 
Q