【问题标题】:How to write plutil command correctly (array and strings)如何正确编写 plutil 命令(数组和字符串)
【发布时间】:2015-10-21 23:03:52
【问题描述】:

我需要通过终端在 Info.plist 文件中添加以下行:

<key>SBAppTags</key>
<array>
<string>hidden</string>
</array>

请告诉我应该在命令行中写什么来得到上面的行?

我尝试过类似的方法:

  • plutil -key SBAppTags -arrayadd -string hidden Info.plist

但没有运气......

【问题讨论】:

    标签: ios command-line terminal


    【解决方案1】:

    您应该采用您想要使用的 XML 格式并将其放入命令中,但在删除其中的“Key”之后,因为它已在“-insert”选项之后输入,以及任何空格。

    数组的输入方式如下:

    plutil -insert SBAppTags -xml "<array><string> hidden </string></array>" Info.plist 
    

    这是字典的输入方式:

    plutil -insert SBAppTags -xml "<dict><key>myFirstKey</key><string>hidden</string></dict>" Info.plist
    

    【讨论】:

      【解决方案2】:

      在 macOS Monterey 上,您可以通过几个步骤以更直接的方式执行此操作:

      #!/bin/zsh
      
      plutil -create xml1 Info.plist # create an empty file [optional]
      
      # insert an empty array
      plutil -insert SBAppTags -array Info.plist 
      
      # append a string to the array
      plutil -insert SBAppTags -string hidden -append Info.plist 
      

      结果是:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
          <key>SBAppTags</key>
          <array>
              <string>hidden</string>
          </array>
      </dict>
      </plist>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-27
        • 1970-01-01
        相关资源
        最近更新 更多