【问题标题】:Modify sub key in *plist files修改 *plist 文件中的子键
【发布时间】:2011-01-22 05:05:00
【问题描述】:

我想修改 plist 文件中的子键(即“TB 项目标识符”):

NSNavPanelExpandedStateForSaveMode = 1;
NSPreferencesContentSize = "{508, 413}";
NSPreferencesSelectedIndex = 6;
"NSToolbar Configuration BrowserWindowToolbarIdentifier" =     {
    "TB Display Mode" = 2;
    "TB Icon Size Mode" = 1;
    "TB Is Shown" = 1;
    "TB Item Identifiers" =         (
        BackForwardToolbarIdentifier,
        HomeToolbarIdentifier,
        InputFieldsToolbarIdentifier
    );
    "TB Size Mode" = 1;
    "TB Visibility Priority Values" =         {
        BackForwardToolbarIdentifier =             (
            999
        );
        InputFieldsToolbarIdentifier =             (
            1000
        );
    };
};

我在 shell 脚本中使用以下命令:

defaults write com.apple.file key keyvalue

所以每次我想更改“TB 项目标识符”时,我都会修改整个“NSToolbar 配置 BrowserWindowToolbarIdentifier”。如何直接修改plist子键或子子键?

【问题讨论】:

    标签: shell scripting macos plist


    【解决方案1】:

    使用 PlistBuddy

    /usr/libexec/PlistBuddy -c "set Key:SubKey1:SubKey2:Subkey3 value" ./Path/To/Your.plist

    【讨论】:

    • 这看起来也是一个不错的系统管理工具。我正在寻找一种在 MacOS X 10.7(又名 Lion)中关闭 appstoreupdateagent 脚本的方法。
    • 但是,PlistBuddy 是针对 plists 的,而 defaults 命令是针对默认数据库的。默认值作为 plist 缓存在磁盘上是一个实现细节。不保证(和内存中的不一样)
    【解决方案2】:
    defaults write com.yourcompany.app key -dict-add subkey plistValue
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      相关资源
      最近更新 更多