• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Creating a plist file in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating a plist file in Applescript


  • Subject: Creating a plist file in Applescript
  • From: Jim Brandt <email@hidden>
  • Date: Tue, 01 Oct 2013 08:17:41 -0500

I have a question about initializing a plist file. Specifically, a plist file tahe is an array of arrays (list of lists).

I have read Luther Fuller's "Property List Tutorial". I have built plist files that have a single key that references a list of lists. What I want to do is eliminate the key and make a plist whose record structure is a list of lists with no key.

I can build this structure via Xcode. However, I can't figure out how to build it from Applescript.

Here is the example I put together. First the plist file, test.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">
<array>
<array>
<string>Array 1 String 1</string>
<string>Array 1 String 2</string>
<string>Array 1 String 3</string>
</array>
<array>
<string>Array 2 String 1</string>
<string>Array 2 String 2</string>
<string>Array 2 String 3</string>
<string>Array 2 String 4</string>
</array>
</array>
</plist>

Building this in Xcode, I can read it, extract the lists and do what I want with the data.

set DesktopPath to (path to desktop) as text
set TestPlist to DesktopPath & "Test.plist"
tell application "System Events" to set PlistRecord to value of property list file TestPlist
set List1 to item 1 of PlistRecord
set List2 to item 2 of PlistRecord

Following Luther's example, to make a new plist file I attempt to initialize it using a shell command. If I use the one in Luther's tutorial, it makes a plist file with a single key referencing a string. I can't replace the record with one that has no key.

So, I need to initialize a plist file that creates that structure. So I tried adding the following:

set PName to quoted form of ((POSIX path of DesktopPath) & "New Test.plist")
set cmd to "defaults write " & PName & " '{ { } }'"
do shell script cmd
tell application "System Events" to set value of property list file PName to PlistRecord

I get an error:

"2013-10-01 08:07:36.529 defaults[29904:f07] Could not parse: { { } }.  Try single-quoting it." number 1

First off, it is single-quoted. If I type this command directly into Terminal, I get the same result.

So, my question is, is there a way to initialize, from Applescript, a plist file that is an array of arrays with no key?

TIA,

Jim Brandt
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Creating a plist file in Applescript
      • From: Luther Fuller <email@hidden>
    • Re: Creating a plist file in Applescript
      • From: Shane Stanley <email@hidden>
  • Next by Date: Re: Creating a plist file in Applescript
  • Next by thread: Re: Creating a plist file in Applescript
  • Index(es):
    • Date
    • Thread