• 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
Re: Possible to Get Property List Editor Edit Plist File?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible to Get Property List Editor Edit Plist File?


  • Subject: Re: Possible to Get Property List Editor Edit Plist File?
  • From: red_menace <email@hidden>
  • Date: Wed, 09 Jun 2010 17:30:03 -0600

Hello

I use a matched get/set pair of handlers that use System Events to get
elements by key name or index.  I didn't have an Automator workflow that
had the "gridSpacing" element lying around, so in the following example I
just grabbed the first element (indexes are 1-based).


on run -- example
set plistFile to (choose file without invisibles)
set theValue to (getPlistElement from {plistFile, "actions", 2, "action", "ActionParameters", 1})


if result is not null then try -- show the element
if (class of theValue) is in {list, record} then (theValue as number) -- force an error
display alert "value:" message (theValue as text)
on error errmess -- lists and records don't format very well, so cheat
set {here, there} to {(offset of "{" in errmess), -(offset of "}" in (reverse of text items of errmess) as text)}
display alert "value:" message text here thru there of errmess
end try
end run


to getPlistElement from plistItems
(*
get the specified element from a Plist structure by name or index
note that the elements are not necessarily in the order shown by the Property List Editor
    the number of items is not fixed, but must be at least 2 (the Plist file and a Plist element)
  parameters: plistItems [list] -
item 1 [mixed]: the Plist file path (Finder or POSIX)
item 2 [mixed]: the Plist element name or index (names are case sensitive)
item(s) 3+ [mixed]: sub item(s)
returns [mixed]: contents of the element, null if not found or error
*)
try
if (count plistItems) is less than 2 then error "getPlistElement handler:  item list contains too few items"
tell application "System Events"
set thePlistElement to property list file ((first item of plistItems) as text) -- start at the root element


repeat with anItem in rest of plistItems -- add on the sub items
set anItem to the contents of anItem
try
set anItem to anItem as integer -- index number?   (indexes start at 1)
end try
set thePlistElement to (get property list item anItem of thePlistElement)
end repeat


return value of thePlistElement
end tell
on error errorMessage number errorNumber
log errorMessage
return null -- error "getPlistElement handler:  element not found (" & ErrorNumber & ")"
end try


end getPlistElement


to setPlistElement from plistItems to someValue
(*
set the specified (existing) element of a Plist structure (by name or index) to someValue
note that the elements are not necessarily in the order shown by the Property List Editor
    the number of items is not fixed, but must be at least 2 (the Plist file and a Plist element)
  parameters: plistItems [list] -
item 1 [mixed]: the Plist file path (Finder or POSIX)
item 2 [mixed]: the Plist element name or index (names are case sensitive)
item(s) 3+ [mixed]: sub item(s)
someValue [mixed]: the value to set
returns [boolean]: true if successful, false if not
*)
try
if (count plistItems) is less than 2 then error "getPlistElement handler:  item list contains too few items"
tell application "System Events"
set thePlistElement to property list file ((first item of plistItems) as text) -- start at the root element


repeat with anItem in rest of plistItems -- add on the sub items
set anItem to the contents of anItem
try
set anItem to anItem as integer -- index number?   (indexes start at 1)
end try
set thePlistElement to (get property list item anItem of thePlistElement)
end repeat


set value of thePlistElement to someValue
set property list file ((first item of plistItems) as text) to thePlistElement -- update plist file
return true
end tell
on error errorMessage number errorNumber
log errorMessage
return false -- error "getPlistElement handler:  element not found (" & ErrorNumber & ")"
end try


end setPlistElement


Dave



On Wed, 9 Jun 2010 05:15:58 +0900, (4) GMAIL 5278 wrote:

Hello.  I normally use Defaults to view and edit plist values if the  
list is not complicated.  When I want to access a value under an  
extensive array of strings, I don't know how to do it.  In one  
particular case, Apple's Property List Editor shows

Root
actions
0
1
action
ActionParameters
gridSpacing
...
...
2
3
AMApplicationBuild
AMApplicationVersion
...
...



 _______________________________________________
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: Possible to Get Property List Editor Edit Plist File?
      • From: "(4) GMAIL 5278" <email@hidden>
  • Prev by Date: Re: Filemaker and Database events
  • Next by Date: Re: Possible to Get Property List Editor Edit Plist File?
  • Previous by thread: Re: Possible to Get Property List Editor Edit Plist File?
  • Next by thread: Re: Possible to Get Property List Editor Edit Plist File?
  • Index(es):
    • Date
    • Thread