#cp.app.prefs

Provides access to application preferences, typically stored via NSUserDefaults or CFProperties. To access the preferences, simply pass in the Bundle ID (eg. "com.apple.Preview") and it will return a table whose keys can be accessed or updated, or iterated via ipairs.

For example:

local previewPrefs = require "cp.app.prefs" "com.apple.Preview" previewPrefs.MyCustomPreference = "Hello world" print(previewPrefs.MyCustomPreference) --> "Hello world" for k,v in pairs(previewPrefs) do print(k .. " = " .. tostring(v)) end

#API Overview

Functions - API calls offered directly by the extension

Constructors - API calls which return an object, typically one that offers API methods


#API Documentation

#Functions

Signaturecp.app.prefs.bundleID(prefs) -> string
TypeFunction
DescriptionRetrieves the bundleID associated with the cp.app.prefs instance.
Parameters
  • prefs - the prefs object to query
Returns
  • The Bundle ID string, or nil if it's not a cp.app.prefs.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/app/prefs.lua line 122

Signaturecp.app.prefs.get(prefs, key[, defaultValue]) -> value
TypeFunction
DescriptionRetrieves the specifed key from the provided prefs. If there is no current value, the defaultValue is returned.
Parameters
  • prefs - The prefs instance.
  • key - The key to retrieve.
  • defaultValue - The value to return if none is currently set.
Returns
  • The current value, or defaultValue if not set.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/app/prefs.lua line 162

Signaturecp.app.prefs.is(thing) -> boolean
TypeFunction
DescriptionChecks if the thing is a cp.app.prefs instance.
Parameters
  • thing - The value to check
Returns
  • true if if's a prefs, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/app/prefs.lua line 109

Signaturecp.app.prefs.prop(prefs, key[, defaultValue[, deepTable]]) -> cp.prop
TypeFunction
DescriptionRetrieves the cp.prop for the specified key. It can be watched for changes. Subsequent calls will return the same cp.prop instance.
Parameters
  • prefs - The prefs instance.
  • key - The key to get/set.
  • defaultValue - The value if no default values is currently set (defaults to nil).
  • deepTable - Should the prop use deep table (defaults to true).
Returns
  • The cp.prop for the key.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/app/prefs.lua line 222

Signaturecp.app.prefs.set(prefs, key, value[, defaultValue]) -> none
TypeFunction
DescriptionSets the key/value for the specified prefs instance.
Parameters
  • prefs - The prefs instance.
  • key - The key to set.
  • value - the new value.
  • defaultValue - The default value.
Returns
  • Nothing.
Notes
  • If the value equals the defaultValue, the preference is removed rather than being set.
ExamplesNone
Sourcesrc/extensions/cp/app/prefs.lua line 186

#Constructors

Signaturecp.app.prefs(bundleID) -> cp.app.prefs
TypeConstructor
DescriptionCreates a new cp.app.prefs instance, pointing at the specified bundleID.
Parameters
  • bundleID The Bundle ID to access preferences for.
Returns
  • A new cp.app.prefs with read/write access to the application's preferences.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/app/prefs.lua line 94