Falafoni

Q: 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:

 

Screen Shot 2014-05-06 at 12.35.02 PM.png

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

Close

Q: Problem with creating a plist file using AppleScript (defaults)

  • All replies
  • Helpful answers

  • by Falafoni,Solvedanswer

    Falafoni Falafoni May 6, 2014 5:37 AM in response to Falafoni
    Level 1 (0 points)
    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>\";"

  • by Cagliostro2,

    Cagliostro2 Cagliostro2 Jul 20, 2015 1:35 PM in response to Falafoni
    Level 1 (5 points)
    Mac OS X
    Jul 20, 2015 1:35 PM in response to Falafoni

    This is vaguely off-topic, but I couldn't find an explanation elsewhere: can you please tell me what "try single-quoting it" means?  I got the same message in terminal and don't know what to do next.