Re: Preferred AS editing tools
Re: Preferred AS editing tools
- Subject: Re: Preferred AS editing tools
- From: "Zavatone, Alex" <email@hidden>
- Date: Thu, 28 Jul 2011 15:42:48 -0700
- Acceptlanguage: en-US
- Thread-topic: Preferred AS editing tools
On Jul 28, 2011, at 4:34 PM, Bruce Robertson wrote:
>
> On Jul 28, 2011, at 1:59 PM, Emmanuel LEVY wrote:
>
>> There have been very good posts about the editing tools, and also the key-value pairs arrays, aka associative arrays.
>>
>> I have a piece of technical news about key-value pairs: Satimage's XMLLib now supports the following new syntax.
>>
>> set p to PlistNew -- this makes an empty dictionary, and has always done so
>> PlistSet p to {firstname: "John", lastname: "Doe", age: 28} -- this has always worked: records are AppleScript's structure for associative arrays.
>> PlistSet p to {"firstname", "John", "lastname", "Doe", "age", 28, "what's his job???", "Bus driver"} -- now you can easily feed a plist with arbitrary keys.
>>
>> Emmanuel
>>
>
> Hm, which version exactly? I get:
>
> error "Incompatible types of 'to' and direct parameters of PlistSet" number -1
I built my key/value pair array applescript implementation to be able to use firstname and lastname as strings, or any AS data type
You'd use it like so:
set myKVPList to MakePropList()
set myKVPList to AddAProp(myKVPList, "first name", "John")
set myKVPList to AddAProp(myKVPList, "last name", "Doe")
set myKVPList to AddAProp(myKVPList, "age", 28)
And to get values by property from lists:
set myVar to GetAProp(myKVPList, "First Name")
log myVar
-- "John"
You can add a prop as above, or simply do AddProp(myList, myProp) and that will populate the KVP list with a default value which you can change.
Handlers/methods are:
MakePropList()
-- returns the proplist ref
AddAProp(myPropList, propNameVariable or string, value
-- Adds the property and value to the list
AddProp(myPropList, propNameVariable or string)
-- Adds the prop to the list with a default value
DeleteProp(myPropList, myProp)
-- removes that prop and the value for it from the list
DeletePropAt(myPropList, myIndex)
-- removes the prop and the value for it from a specific position within the list
SetProp(myPropList, myProp, myVal)
-- sets the specific property's value
GetAProp(myPropList, myProp)
-- returns the value for that prop
GetPropAt(myPropList, myIndex)
-- returns the prop name for that prop at a specific position within the array
GetValueAt(myPropList, myIndex)
-- returns the value for that prop at a specific position within the array
GetPropListCount(myPropList)
-- returns the # of entries in the proplist
DisplayPropList(myPropList, myDelimiter)
-- returns a comma or return delimited string of each KVP pair in the list
DisplayNestedPropList(myListofLists)
-- returns a comma delimited string of each KVP pair in nested KVP lists
DisplayPropListInXML(myPropList)
-- returns a proplist in XML string format
DisplayNestedPropListInXML(myListofLists)
-- returns a nested proplist in XML string format
This email message and any attachments are for the sole use of the intended recipient(s) and may contain information that is proprietary to U.S. Foodservice, Inc and/or its subsidiaries or otherwise confidential or legally privileged. If you have received this message in error, please notify the sender by reply, and delete all copies of this message and any attachments. If you are the intended recipient you may use the information contained in this message and any files attached to this message only as authorized by U.S. Foodservice. Files attached to this message may only be transmitted using secure systems and appropriate means of encryption, and must be secured using the same level password and security protection with which the file was provided to you. Any unauthorized use, dissemination or disclosure of this message or it's attachments is strictly prohibited.
_______________________________________________
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