Bash syntax writing to XML files with CLI. Error «Defaults: Unexpected argument notification»

Hello,


I want to create a property list file by supplying an XML-type nested argument. It fails with the error "Defaults: Unexpected argument notification" you see in the subject.


bash shell


My command is


defaults write org.SmartSolutions.DummyDomain.plist \ '<dict>
> <key>Label</key>
> <string>org.SmartSolutions.DummyDomain</string>
> <key>ProgramArguments</key>
> <array>
> <string>/bin/sh</string>
> <string>-c</string>
> <string>/usr/bin/osascript -e 'delay 5'  && /usr/bin/osascript -e 'display notification "Started Squid" '</string>
</array>
> <key>RunAtLoad</key>
</true>
> <key>StandardErrorPath</key>
> <string>/Users/home_redacted/Documents/My Launch Agents Logs/org.SmartSolutions.DummyDomain-err.log</string>
> <key>StandardOutPath</key>
> <string>/Users/home_redacted/Documents/My Launch Agents Logs/org.SmartSolutions.DummyDomain-out.log</string>
> </dict>'


Where's my mistake? What argument was "unexpected"?

Posted on Sep 18, 2020 12:52 PM

Reply

Similar questions

1 reply

Sep 18, 2020 5:42 PM in response to scrutinizer82

I found a root of the problem so I'm replying to my own OP in case someone runs into the same issue. The solution is that according to the official XML 1.0 specification:


  • Double quotes must be escaped as "&quot;" (the quotation marks are to be omitted inside an XML file)
  • Single quotes must be escaped as "&apos;" (the quotation marks are to be omitted inside an XML file, "apos" stands for apostrophe)
  • Ampersands must be escaped as "&amp;" (the quotation marks are to be omitted inside an XML file).


So, with the CLI my XML file should've been formed as


defaults write org.SmartSolutions.DummyDomain.plist \ '
<dict>
<key>Label</key>
<string>org.SmartSolutions.DummyDomain</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/usr/bin/osascript -e &apos;delay 5&apos; &amp;&amp;  usr/bin/osascript -e &apos;display notification &quot;Started Squid&quot;&apos;</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/home_redacted/Documents/My Launch Agents Logs/org.SmartSolutions.DummyDomain-err.log</string>
<key>StandardOutPath</key>
<string>/Users/home_redacted/Documents/My Launch Agents Logs/org.SmartSolutions.DummyDomain-out.log</string>
</dict>'

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Bash syntax writing to XML files with CLI. Error «Defaults: Unexpected argument notification»

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.