# 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

  • bundleID
  • get
  • is
  • prop
  • set

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

  • prefs

# API Documentation

# Functions

# bundleID

Signature cp.app.prefs.bundleID(prefs) -> string
Type Function
Description Retrieves 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.
Notes None
Examples None
Source src/extensions/cp/app/prefs.lua line 122

# get

Signature cp.app.prefs.get(prefs, key[, defaultValue]) -> value
Type Function
Description Retrieves 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.
Notes None
Examples None
Source src/extensions/cp/app/prefs.lua line 162

# is

Signature cp.app.prefs.is(thing) -> boolean
Type Function
Description Checks if the thing is a cp.app.prefs instance.
Parameters
  • thing - The value to check
Returns
  • true if if's a prefs, otherwise false.
Notes None
Examples None
Source src/extensions/cp/app/prefs.lua line 109

# prop

Signature cp.app.prefs.prop(prefs, key[, defaultValue[, deepTable]]) -> cp.prop
Type Function
Description Retrieves 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.
Notes None
Examples None
Source src/extensions/cp/app/prefs.lua line 222

# set

Signature cp.app.prefs.set(prefs, key, value[, defaultValue]) -> none
Type Function
Description Sets 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.
Examples None
Source src/extensions/cp/app/prefs.lua line 186

# Constructors

# prefs

Signature cp.app.prefs(bundleID) -> cp.app.prefs
Type Constructor
Description Creates 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.
Notes None
Examples None
Source src/extensions/cp/app/prefs.lua line 94