Problem with creating a plist file using AppleScript (defaults)

Question 1


I am trying to use this script:


do shell script "defaults write ~/Desktop/com.test Directory1 \"<dict><key>Directory2</key><dict>\\
<key>Directory3</key><dict>\\
<key>Number1</key><integer>1</integer>\\
<key>String1</key><string>String1</string>\\
<key>Boolean1</key><bool>TRUE</bool>\\
</dict></dict></dict></dict>\";"


to create a plist file that will look like this:


User uploaded file

However, the script will return this error:


error "2014-05-06 12:38:26.927 defaults[3003:f07] Could not parse: <dict><key>Directory2</key><dict><key>Directory3</key><dict><key>Number1</key>< integer>1</integer><key>String1</key><string>String1</string><key>Boolean1</key> <bool></bool></dict></dict></dict></dict>. Try single-quoting it." number 1


as soon as I try to add Boolean1. If I remove this line from the script:


<key>Boolean1</key><bool>TRUE</bool>\\


the script will work and create a com.test.plist file on the Desktop that will look like on the screenshot above, but (of course) with no boolean. What am I doing wrong?



Question 2


How can I read the value of "Number1" using Terminal? How should the "defaults read" command look like?

OS X Mavericks (10.9.2)

Posted on May 6, 2014 3:51 AM

Reply
2 replies

May 6, 2014 5:37 AM in response to Falafoni

Please ignore the first question. The code should look like this:


do shell script "defaults write ~/Desktop/com.test Directory1 \"<dict><key>Directory2</key><dict>\\
<key>Directory3</key><dict>\\
<key>Number1</key><integer>1</integer>\\
<key>String1</key><string>String1</string>\\
<key>Boolean1</key><true/>\\

</dict></dict></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.

Problem with creating a plist file using AppleScript (defaults)

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