DEFAULTS(1) | General Commands Manual | DEFAULTS(1) |
defaults
— access
the Mac OS X user defaults system
defaults |
[-currentHost | -host
hostname] read [domain
[key]] |
defaults |
[-currentHost | -host
hostname] read-type domain
key |
defaults |
[-currentHost | -host
hostname] write domain
{ 'plist' |
key 'value' } |
defaults |
[-currentHost | -host
hostname] rename domain old_key
new_key |
defaults |
[-currentHost | -host
hostname] delete [domain
[key]] |
defaults |
[-currentHost | -host
hostname] {
domains | find word |
help } |
Defaults
allows users to read, write, and
delete Mac OS X user defaults from a command-line shell. Mac OS X
applications and other programs use the defaults system to record user
preferences and other information that must be maintained when the
applications aren't running (such as default font for new documents, or the
position of an Info panel). Much of this information is accessible through
an application's Preferences panel, but some of it isn't, such as the
position of the Info panel. You can access this information with
defaults
Note: Since applications do access the defaults system while they're running, you shouldn't modify the defaults of a running application. If you change a default in a domain that belongs to a running application, the application won't see the change and might even overwrite the default.
User defaults belong to domains, which typically correspond to individual applications. Each domain has a dictionary of keys and values representing its defaults; for example, "Default Font" = "Helvetica". Keys are always strings, but values can be complex data structures comprising arrays, dictionaries, strings, and binary data. These data structures are stored as XML Property Lists.
Though all applications, system services, and other programs have their own domains, they also share a domain named NSGlobalDomain. If a default isn't specified in the application's domain, but is specified in NSGlobalDomain, then the application uses the value in that domain.
The commands are as follows:
defaults write com.companyname.appname "Default Color" '(255, 0, 0)'
sets the value for Default Color to an array containing the strings 255, 0, 0 (the red, green, and blue components). Note that the key is enclosed in quotation marks because it contains a space.
defaults write com.companyname.appname '{ "Default Color" = (255, 0, 0); "Default Font" = Helvetica; }';
erases any previous defaults for com.companyname.appname and writes the values for the two names into the defaults system.
Specifying domains:
defaults read com.apple.TextEdit
-app
applicationdefaults read -app TextEdit
defaults read ~/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit.plist
normally gives the same result as the two previous examples. In the following example:
defaults write ~/Desktop/TestFile foo bar
will write the key 'foo' with the value 'bar' into the plist file 'TestFile.plist' that is on the user's desktop. If the file does not exist, it will be created. If it does exist, the key-value pair will be added, overwriting the value of 'foo' if it already existed.
WARNING: The defaults command will be changed in an upcoming major release to only operate on preferences domains. General plist manipulation utilities will be folded into a different command-line program.
-g
|
-globalDomain
|
NSGlobalDomainSpecifying value types for preference keys:
defaults
will assume
the value is a string. For best results, use one of the type flags, listed
below.-string
-data
-int[eger]
-float
-bool[ean]
-date
-array
defaults write somedomain preferenceKey -array element1 element2 element3
The specified array overwrites the value of the key if the key was present at the time of the write. If the key was not present, it is created with the new value.
-array-add
-dict
defaults write somedomain preferenceKey -dict key1 value1 key2 value2
The specified dictionary overwrites the value of the key if the key was present at the time of the write. If the key was not present, it is created with the new value.
-dict-add
Specifying a host for preferences:
Operations on the defaults database normally apply to any host the user may log in on, but may be restricted to apply only to a specific host.
-currentHost
-host
hostnameDefaults can be structured in very complex ways, making it difficult for the user to enter them with this command.
First appeared in NeXTStep.
November 3, 2003 | Mac OS X |