LoginSignup
5
3

More than 1 year has passed since last update.

MacOS PlistBuddyコマンドを使ってplistファイルを自由に編集しよう

Last updated at Posted at 2020-10-21

PlistBuddyコマンド

Macにデフォルトで入っているplistに対して様々な処理を行えるコマンドです。

plistに関しては、plutilコマンドがありますが、データが階層になっているファイルはplutilコマンドでは編集できません。

詳細についてはhelpコマンドで中身を見てもらうとして、よく使うplistファイルの編集コマンドのみ説明します。

$ /usr/libexec/PlistBuddy   
Usage: PlistBuddy [-cxh] <file.plist>
    -c "<command>" execute command, otherwise run in interactive mode
    -x output will be in the form of an xml plist where appropriate
    -h print the complete help info, with command guide

$ /usr/libexec/PlistBuddy -h    
Command Format:
    Help - Prints this information
    Exit - Exits the program, changes are not saved to the file
    Save - Saves the current changes to the file
    Revert - Reloads the last saved version of the file
    Clear [<Type>] - Clears out all existing entries, and creates root of Type
    Print [<Entry>] - Prints value of Entry.  Otherwise, prints file
    Set <Entry> <Value> - Sets the value at Entry to Value
    Add <Entry> <Type> [<Value>] - Adds Entry to the plist, with value Value
    Copy <EntrySrc> <EntryDst> - Copies the EntrySrc property to EntryDst
    Delete <Entry> - Deletes Entry from the plist
    Merge <file.plist> [<Entry>] - Adds the contents of file.plist to Entry
    Import <Entry> <file> - Creates or sets Entry the contents of file

Entry Format:
    Entries consist of property key names delimited by colons.  Array items
    are specified by a zero-based integer index.  Examples:
        :CFBundleShortVersionString
        :CFBundleDocumentTypes:2:CFBundleTypeExtensions

Types:
    string
    array
    dict
    bool
    real
    integer
    date
    data

Examples:
    Set :CFBundleIdentifier com.apple.plistbuddy
        Sets the CFBundleIdentifier property to com.apple.plistbuddy
    Add :CFBundleGetInfoString string "App version 1.0.1"
        Adds the CFBundleGetInfoString property to the plist
    Add :CFBundleDocumentTypes: dict
        Adds a new item of type dict to the CFBundleDocumentTypes array
    Add :CFBundleDocumentTypes:0 dict
        Adds the new item to the beginning of the array
    Delete :CFBundleDocumentTypes:0 dict
        Deletes the FIRST item in the array
    Delete :CFBundleDocumentTypes
        Deletes the ENTIRE CFBundleDocumentTypes array


表示

syntax

$ /usr/libexec/PlistBuddy -c "print" <表示したいplistファイルのパス>

xml形式での表示

xml形式で表示したい場合は xオプションを付与します。

$ /usr/libexec/PlistBuddy -x -c "print" <表示したいplistファイルのパス>

実例

$ /usr/libexec/PlistBuddy -c "print" ~/Library/Preferences/com.apple.speech.voice.prefs.plist
Dict {
    LastClientIDFromSpeakingHotkey = com.google.Chrome
    SelectedVoiceID = 369275107
    VoiceRateDataArray = Array {
        Array {
            1886745202
            369275107
            720
        }
        Array {
            1886745202
            369275117
            720
        }
    }
}

表示の範囲指定

配列名を指定することでより範囲を限定して表示することもできます。

syntax

$ /usr/libexec/PlistBuddy -c "print [配列名]:[配列のindex]" <plistファイルのパス>

実例

$ /usr/libexec/PlistBuddy -c "print VoiceRateDataArray:0" ~/Library/Preferences/com.apple.speech.voice.prefs.plist
Array {
    1886745202
    369275107
    720
}

編集

syntax

場所を指定して、スペースを開けて変えたい値を入れます。

$ /usr/libexec/PlistBuddy -c "set [配列名]:[配列のindex]:[配列のindex]... [値]" ~/Library/Preferences/com.apple.speech.voice.prefs.plist

実例

$ /usr/libexec/PlistBuddy -c "set VoiceRateDataArray:0:2 360" ~/Library/Preferences/com.apple.speech.voice.prefs.plist
~
$ /usr/libexec/PlistBuddy -c "print VoiceRateDataArray:0" ~/Library/Preferences/com.apple.speech.voice.prefs.plist
Array {
    1886745202
    369275107
    360
}

変更後は再起動するか、以下のコマンドを実施して、設定を反映させてください。

killall com.apple.speech.speechsynthesisd
killall SpeechSynthesisServer
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3