Re: get properties treating variable as literal - lightbulb moment
Re: get properties treating variable as literal - lightbulb moment
- Subject: Re: get properties treating variable as literal - lightbulb moment
- From: Christopher Nebel <email@hidden>
- Date: Wed, 4 Oct 2006 21:39:19 -0700
On Oct 4, 2006, at 7:58 PM, Jaime Magiera wrote:
Duh. Sorry Chris. It took a second. In my defense, I'm working on 4
different projects in 3 different languages right now =)
New methods...
-- A method for reading from a preferences file.
on read_from_preferences(aFile, aPreference)
try
tell application "System Events"
set returnValue to property list items of property list item
aPreference of contents of property list file aFile
end tell
return returnValue
on error err
return err
end try
end read_from_preferences
-- If there are preference objects defined in the preferences, the
method below creates an array of Unique IDs of those objects.
if (currentPreferencesArray is not equal to {}) then
set currentUniqueKeys to {}
repeat with aPreferenceObject in currentPreferencesArray
tell application "System Events"
set uniqueKeyValue to (value of (get property list item
uniqueKey of aPreferenceObject))
end tell
copy uniqueKeyValue to end of currentUniqueKeys
end repeat
else
set currentUniqueKeys to {}
end if
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"}
This will return an empty list if there are no items in "Servers";
there's no need to test for that condition.
--Chris Nebel
AppleScript Engineering
_______________________________________________
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