Re: get properties treating variable as literal
Re: get properties treating variable as literal
- Subject: Re: get properties treating variable as literal
- From: Jaime Magiera <email@hidden>
- Date: Wed, 4 Oct 2006 22:18:57 -0400
On Oct 4, 2006, at 7:17 PM, Christopher Nebel wrote:
Do you mean System Events' Property List Suite? If so, then you
asked it for the wrong thing. People tend to ask for "value
of ...", get a record, and then forget that there's an object model
below that, too. For example, if you wanted to get all of the keys
as strings, you could say something like this:
tell application "System Events"
set f to file "com.apple.dashboard.plist" of the preferences folder
set p to property list file (path of f)
get name of every property list item of p
end tell
--> {"other-gadgets", "locale", "tilde-mod", "widget-list", "layer-
gadgets", "slash-mod"}
Now that you have a list of strings, you can ask for individual
values by their key name, such as...
value of property list item "locale" of p
--> "en_US"
I'm having a hard time wrapping my head around what you're saying.
Below is the method I use to get the "servers" from the preference file:
-- A method for reading from a preferences file.
on read_from_preferences(aFile, aPreference)
try
tell application "System Events"
set returnValue to get value of 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
-- Here is how I call it
set currentServers to read_from_preferences((preferencesPlist as
string), "Servers")
-- which returns an array of servers, each one of which also has keys.
{{|displayName|:"black", |hostName|:"not applicable", protocol:"Local
Folder", |baseURL|:"http://fakeurl.com", |remotePath|:"not
applicable", |userName|:"not applicable", |uniqueServerID|:
99.763908842249, |memberName|:"not applicable"}, {|
displayName|:"yellow", |hostName|:"not applicable", protocol:"Local
Folder", |baseURL|:"http://anotherfakeurl.com", |remotePath|:"not
applicable", |userName|:"not applicable", |uniqueServerID|:109.45973,
|memberName|:"not applicable"} }
Now, in all the other programming languages I work with the array use
key-value coding, I would would iterate through the list and and
obtain a value for a particular key of each object...
repeat with i in the list
get "taco" of i
end repeat
In WebObjects (Java), it's just
aServer.valueForKey(aVariable)
In this case...
if (currentPreferencesArray is not equal to {}) then
repeat with aPreferenceObject in currentPreferencesArray
copy (get aVariable of aServer) to end of currentUniqueKeys
end repeat
else
set currentUniqueKeys to {}
end if
In your example, how would I compare a key of an *item* of "widget-
list"?
I'll going to be working on this all night and perhaps I'll have a
lightbulb moment.
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