Re: key,value pairs
Re: key,value pairs
- Subject: Re: key,value pairs
- From: Malcolm Fitzgerald <email@hidden>
- Date: Thu, 19 Jun 2003 11:29:45 +1000
>
It seems that, unlike Perl hashes or Python dictionaries, Applescript records
>
can only be accessed by a literal, not by a string -- is this correct ?
>
Yes
>
What is the typical way of doing this sort of thing in Applescript ?
>
perhaps not typical.
--
on asa_keys()
return my asa_preferences("list keys")
end asa_keys
--
--
on asa_values()
return my asa_preferences("list values")
end asa_values
--
--
on asa_preferences(x)
-- x is a string: "record", "list keys", "list values"
--
set _handler to "asa_preferences(" & x & ")/ prefs_lib"
--
if x is not in {"record", "list keys", "list values"} then
return {"Error", _handler, 0, "bad parameter"}
--
set pref_record to {}
set fPath to (path to preferences folder) as string
set fPath to "" & fPath & "ASA preferences"
--
try
copy (read file fPath) to mPrefs
--
set text item delimiters to return
set mPrefs to every text item of mPrefs
set text item delimiters to tab
--
repeat with i in mPrefs
if i contains tab then
if x begins with "list" then -- list
of keys or values
set y to 1 -- keys
if x ends with "values" then set y to 2
set r to text item y of i
else
set s to ("{" & text item 1
of i & ":\"" & text item 2 of i & "\"}")
set r to run script s
end if
set pref_record to pref_record & r
end if
end repeat
--
on error m number n
return {"Error", _handler, n, m}
end try
--
return pref_record
end asa_preferences
--
--
--
Malcolm Fitzgerald email@hidden
Database Manager
http://www.asauthors.org
The Australian Society of Authors ph: 02 93180877 fax: 02 93180530
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.