• 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: get properties treating variable as literal - lightbulb moment
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: get properties treating variable as literal - lightbulb moment


  • Subject: Re: get properties treating variable as literal - lightbulb moment
  • From: Jaime Magiera <email@hidden>
  • Date: Thu, 5 Oct 2006 07:53:46 -0400

It looks like there's a bit missing in between those two steps -- exactly how does uniqueKey get set, and what does it get set to? -- but if currentPreferencesArray came from read_from_preferences, and uniqueKey is a string, say "displayName", then that will work.

It's possible to compact this further, and make it a bit faster to boot, by not trying to evaluate the array too soon. For example:

on read_from_preferences(aFile, aPreference)
tell application "System Events"
return property list item aPreference of property list file aFile -- the "of contents" is optional.
end tell
end R


set currentPreferencesArray to read_from_preferences(..., "Servers")
set uniqueKey to "displayName"
tell application "System Events"
-- look Ma, no loop!
get value of property list item uniqueKey of every property list item of currentPreferencesArray
end tell
set currentUniqueKeys to the result
--> {"black", "yellow"}



Thanks Chris!

Excellent. I always forget about (....every item....) in Applescript. Much better. One last question: How do you write incrementally? or write over a value in a plist? I can get it to work for entries that are empty (e.g. "servers" has no items in it). For example, using the method outlined below, I can add an item to my "servers" plist item if it is empty.

http://lists.apple.com/archives/applescript-users/2006/Sep/msg00013.html

However, I can't seem to write to the "servers" if it already has items. The .plist is wiped clean and no errors are thrown.

By the way, are there any official Applescript examples of using Property List Suite? If not, I'll contribute some to the wikis when this project is over.

Jaime Magiera
Sensory Research Network
http://www.sensoryresearch.net




_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: get properties treating variable as literal - more lightbulb moments
      • From: Jaime Magiera <email@hidden>
References: 
 >get properties treating variable as literal (From: Jaime Magiera <email@hidden>)
 >Re: get properties treating variable as literal (From: Christopher Nebel <email@hidden>)
 >Re: get properties treating variable as literal (From: Jaime Magiera <email@hidden>)
 >Re: get properties treating variable as literal (From: Christopher Nebel <email@hidden>)
 >Re: get properties treating variable as literal (From: Jaime Magiera <email@hidden>)
 >Re: get properties treating variable as literal - lightbulb moment (From: Jaime Magiera <email@hidden>)
 >Re: get properties treating variable as literal - lightbulb moment (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: Can't turn off screen savers in System Preferences
  • Next by Date: Re: get properties treating variable as literal - more lightbulb moments
  • Previous by thread: Re: get properties treating variable as literal - lightbulb moment
  • Next by thread: Re: get properties treating variable as literal - more lightbulb moments
  • Index(es):
    • Date
    • Thread