マニュアルから学ぶMAC defaultsコマンド

MACのdefaultsコマンドについて学習中です。
少しずつまとめていきます。

ターミナルからdefaultsを実行すると、以下の出力が得られます。

takk@makku ~ % defaults
Command line interface to a user's defaults.
Syntax:

'defaults' [-currentHost | -host <hostname>] followed by one of the following:

  read                                 shows all defaults
  read <domain>                        shows defaults for given domain
  read <domain> <key>                  shows defaults for given domain, key

  read-type <domain> <key>             shows the type for the given domain, key

  write <domain> <domain_rep>          writes domain (overwrites existing)
  write <domain> <key> <value>         writes key for domain

  rename <domain> <old_key> <new_key>  renames old_key to new_key

  delete <domain>                      deletes domain
  delete <domain> <key>                deletes key in domain

  import <domain> <path to plist>      writes the plist at path to domain
  import <domain> -                    writes a plist from stdin to domain
  export <domain> <path to plist>      saves domain as a binary plist to path
  export <domain> -                    writes domain as an xml plist to stdout
  domains                              lists all domains
  find <word>                          lists all entries containing word
  help                                 print this help

<domain> is ( <domain_name> | -app <application_name> | -globalDomain )
         or a path to a file omitting the '.plist' extension

<value> is one of:
  <value_rep>
  -string <string_value>
  -data <hex_digits>
  -int[eger] <integer_value>
  -float  <floating-point_value>
  -bool[ean] (true | false | yes | no)
  -date <date_rep>
  -array <value1> <value2> ...
  -array-add <value1> <value2> ...
  -dict <key1> <value1> <key2> <value2> ...
  -dict-add <key1> <value1> ...
takk@makku ~ %

もう少し詳しく、manを読んでいきます。

(man defaultsより)
DEFAULTS(1)               BSD General Commands Manual              DEFAULTS(1)

NAME
     defaults -- access the Mac OS X user defaults system

もしかしてBSD「Berkeley Software Distribution」の頃からあったってことだろうか。
そのうち調べます。

マニュアルの続きです。

(man defaultsより)
SYNOPSIS
     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コマンドを実行したときにある説明の方が、個人的には見やすいと思います。

(man defaultsより)
DESCRIPTION
     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 sys-
     tem 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

defaultsは、defaultsの設定参照削除がコマンドラインからできるってことなんですが、
defaultsとdefaultsが同じ単語を使っているので、一瞬意味がわかりませんでした。
defaultsコマンドは、デフォルト値を設定参照削除ができるっていうことですね。

     (man 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 applica-
     tions. 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 speci-
     fied in the application's domain, but is specified in NSGlobalDomain, then the
     application uses the value in that domain.

     The commands are as follows:

     read         Prints all of the user's defaults, for every domain, to standard out-
                  put.

     read domain  Prints all of the user's defaults for domain to standard output.

     read domain key
                  Prints the value for the default of domain identified by key.

     read-type domain key
                  Prints the plist type for the given domain identified by key.

     write domain key 'value'
                  Writes value as the value for key in domain.  value must be a prop-
                  erty list, and must be enclosed in single quotes.  For example:

                        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.

     write domain 'plist'
                  Overwrites the defaults information in domain with that given as
                  plist.  plist must be a property list representation of a dictionary,
                  and must be enclosed in single quotes.  For example:

                        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.

     delete domain
                  Removes all default information for domain.

     delete domain key
                  Removes the default named key from domain.

     domains      Prints the names of all domains in the user's defaults system.

     find word    Searches for word in the domain names, keys, and values of the user's
                  defaults, and prints out a list of matches.

     help         Prints a list of possible command formats.

OPTIONS
Specifying domains:

domain    If no flag is specified, domain is a domain name of the form com.compa-
          nyname.appname.  Example:

                defaults read com.apple.TextEdit

-app application
          The name of an application may be provided instead of a domain using the
          -app flag. Example:

                defaults read -app TextEdit

filepath  Domains may also be specified as a path to an arbitrary plist file, with
          or without the '.plist' extension. For example:

                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 'Test-
          File.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 manipula-
          tion utilities will be folded into a different command-line program.

-g | -globalDomain | NSGlobalDomain
          Specify the global domain. '-g' and '-globalDomain' may be used as syn-
          onyms for NSGlobalDomain.

Specifying value types for preference keys:

            If no type flag is provided, defaults will assume the value is a
            string. For best results, use one of the type flags, listed below.

-string     Allows the user to specify a string as the value for the given prefer-
            ence key.

            -data       Allows the user to specify a bunch of raw data bytes as the value for
                        the given preference key.  The data must be provided in hexidecimal.

            -int[eger]  Allows the user to specify an integer as the value for the given pref-
                        erence key.

            -float      Allows the user to specify a floating point number as the value for
                        the given preference key.

            -bool[ean]  Allows the user to specify a boolean as the value for the given pref-
                        erence key.  Value must be TRUE, FALSE, YES, or NO.

            -date       Allows the user to specify a date as the value for the given prefer-
                        ence key.

            -array      Allows the user to specify an array as the value for the given prefer-
                        ence key:

                              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  Allows the user to add new elements to the end of an array for a key
                        which has an array as its value. Usage is the same as -array above. If
                        the key was not present, it is created with the specified array as its
                        value.

            -dict       Allows the user to add a dictionary to the defaults database for a
                        domain.  Keys and values are specified in order:

                              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   Allows the user to add new key/value pairs to a dictionary for a key
                                         which has a dictionary as its value. Usage is the same as -dict above.
                                         If the key was not present, it is created with the specified dictio-
                                         nary as its value.

                             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.

                                       If no host is provided, preferences operations will apply to any host
                                       the user may log in on.

                             -currentHost
                                       Restricts preferences operations to the host the user is currently
                                       logged in on.

                             -host hostname
                                       Restricts preferences operations to hostname.

                        BUGS
                             Defaults can be structured in very complex ways, making it difficult for the user
                             to enter them with this command.

                        HISTORY
                             First appeared in NeXTStep.

                        Mac OS X                          Nov 3, 2003                         Mac OS X




domainってどんなものがあるか。
defaults domainsで表示された結果です。

takk@makku ~ % defaults domains | fmt
ContextStoreAgent, MobileMeAccounts, com.apple.AMPLibraryAgent,
com.apple.AdLib, com.apple.AddressBook, com.apple.AppStore,
com.apple.AppleMediaServices, com.apple.AppleMediaServices.notbackedup,
com.apple.AppleMultitouchMouse, com.apple.AppleMultitouchTrackpad,
com.apple.BKAgentService, com.apple.BezelServices, com.apple.CalendarAgent,
com.apple.CommCenter.counts, com.apple.CoreGraphics,
com.apple.DictionaryServices, com.apple.FolderActionsDispatcher,
com.apple.FontRegistry.user, com.apple.GEO, com.apple.HIToolbox,
com.apple.Maps, com.apple.Preferences, com.apple.Preview,
com.apple.Preview.ImageSizingPresets, com.apple.Preview.ViewState,
com.apple.Safari.SafeBrowsing, com.apple.Safari.SandboxBroker,
com.apple.ScreenTimeAgent, com.apple.ServicesMenu.Services,
com.apple.SetupAssistant, com.apple.SocialPushAgent, com.apple.Spotlight,
com.apple.SystemProfiler, com.apple.TV, com.apple.TelephonyUtilities,
com.apple.Terminal, com.apple.TextInputMenu, com.apple.UserAccountUpdater,
com.apple.accounts, com.apple.accountsd, com.apple.amp.mediasharingd,
com.apple.appstored, com.apple.assistant, com.apple.assistant.backedup,
com.apple.assistant.support, com.apple.bird, com.apple.calculateframework,
com.apple.classroom, com.apple.cloudd, com.apple.cloudpaird,
com.apple.cloudphotod, com.apple.commcenter,
com.apple.commcenter.callservices, com.apple.commerce.knownclients,
com.apple.contacts.donation-agent, com.apple.coreauthd,
com.apple.coreservices.uiagent,
com.apple.coreservices.useractivityd.dynamicuseractivites,
com.apple.corespotlightui, com.apple.dock,
com.apple.driver.AppleBluetoothMultitouch.mouse,
com.apple.driver.AppleBluetoothMultitouch.trackpad,
com.apple.driver.AppleHIDMouse, com.apple.dt.IDECacheDeleteAppExtension,
com.apple.facetime.bag, com.apple.fileproviderd, com.apple.finder,
com.apple.frameworks.diskimages.diuiagent, com.apple.gamecenter,
com.apple.gamed, com.apple.homed, com.apple.homed.notbackedup,
com.apple.iCal, com.apple.iChat, com.apple.iTunes, com.apple.icloud.fmfd,
com.apple.icloud.searchpartyuseragent,
com.apple.identityservices.idstatuscache, com.apple.identityservicesd,
com.apple.ids.deviceproperties, com.apple.ids.subservices,
com.apple.imagecapture, com.apple.imagent,
com.apple.imdpersistence.IMDPersistenceAgent, com.apple.imessage,
com.apple.imessage.bag, com.apple.imservice.ids.FaceTime,
com.apple.imservice.ids.iMessage, com.apple.internal.ck,
com.apple.ipTelephony, com.apple.itunesstored, com.apple.keyboardservicesd,
com.apple.locationmenu, com.apple.loginwindow, com.apple.madrid,
com.apple.mediaanalysisd, com.apple.messages.nicknames, com.apple.mmcs,
com.apple.ncplugin.stocks, com.apple.ncplugin.weather, com.apple.ncprefs,
com.apple.notificationcenterui, com.apple.parsecd, com.apple.passd,
com.apple.photoanalysisd, com.apple.photolibraryd,
com.apple.photos.shareddefaults, com.apple.preference.general,
com.apple.preferences.extensions.ServicesWithUI,
com.apple.preferences.extensions.ShareMenu,
com.apple.proactive.PersonalizationPortrait,
com.apple.quicklook.ThumbnailsAgent, com.apple.rapport,
com.apple.registration, com.apple.remindd, com.apple.remindd.babysitter,
com.apple.routined, com.apple.scheduler, com.apple.screencapture,
com.apple.screencaptureui, com.apple.screensaver, com.apple.scriptmenu,
com.apple.security.KCN,
com.apple.security.cloudkeychainproxy3.keysToRegister,
com.apple.security.ctkd-db, com.apple.security.sosaccount,
com.apple.sharingd, com.apple.siri.context.service,
com.apple.siri.media-indexer, com.apple.spaces, com.apple.stockholm,
com.apple.stocks, com.apple.studentd, com.apple.suggestions,
com.apple.symbolichotkeys, com.apple.systempreferences,
com.apple.systemuiserver, com.apple.talagent,
com.apple.textInput.keyboardServices.textReplacement, com.apple.tourist,
com.apple.touristd, com.apple.universalaccess, com.apple.xpc.activity2,
com.wacom.Wacom-Desktop-Center, knowledge-agent, loginwindow,
org.gimp.gimp-2.10:, pbs,
systemgroup.com.apple.icloud.searchpartyd.sharedsettings
takk@makku ~ %

コメント

タイトルとURLをコピーしました