Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write plutil command correctly (array and strings)

I neet to add following lines into Info.plist file via Terminal:

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

Please tell what I should write in command line to get the lines above?

I tried something like that:

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

but with no luck...

like image 758
Sobchyk Sobov Avatar asked Oct 21 '15 23:10

Sobchyk Sobov


2 Answers

You should take the XML format you'd like to use and put it in the command but after removing the "Key" out of it ,as it has been entered after the "-insert" option, along with any whitespace.

Here's how an array entered:

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

Here's how a dictionary entered:

plutil -insert SBAppTags -xml "<dict><key>myFirstKey</key><string>hidden</string></dict>" Info.plist
like image 56
Mohammad Allam Avatar answered Oct 20 '22 03:10

Mohammad Allam


On macOS Monterey, you can do this in a more straightforward way with a few steps:

#!/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 

The result is:

<?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>
like image 28
Pendarin Avatar answered Oct 20 '22 03:10

Pendarin