This script stores all preferences as “first/second”. Both are in same Sibling. I dont think this is proper way to store prefs. How can i use Array and create New Sibling for every item in list?
set testthis to {"first", "second"}
do shell script ("defaults write Scripts.Test testthis " & testthis)
set testpref to (do shell script "defaults read Scripts.Test testthis")
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set newTxt to text items of testpref
set AppleScript's text item delimiters to tid
set newTxt to newTxt as list
set prefready to item 2 of newTxt
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set testthis to {"first", "second"}
do shell script ("defaults write Scripts.Test testthis -array " & testthis)
set testpref to (do shell script "defaults read Scripts.Test testthis | sed -e 's/^(//' -e 's/)$//'")
set AppleScript's text item delimiters to ", "
set newTxt to text items of testpref
set AppleScript's text item delimiters to tid
set newTxt to newTxt as list
set prefready to item 2 of newTxt
It simply removes ‘(’ and ‘)’ from start and end of the resulting output of the defaults read
I am afraid you’ll have to do a repeat loop search through all list elements - for example:
set mylist to {{nam:"Joe", email:"Joe@work.com", address:"165 XXX", phone:"22929", tex:"lkjlkjk"}, {nam:"Jim", email:"Jim@host.com", address:"165 XXX", phone:"22929", tex:"lkjlkjk"}, {nam:"Joe", email:"Joe@home.com", address:"165 XXX", phone:"22929", tex:"lkjlkjk"}, {nam:"Jane", email:"Jane@aol.com", address:"165 XXX", phone:"22929", tex:"lkjlkjk"}, {nam:"Jeff", email:"Jeff@yahoo.com", address:"165 XXX", phone:"22929", tex:"lkjlkjk"}}
get my searchListforNam("Joe", mylist)
on searchListforNam(theNam, theList)
set retval to {}
repeat with listItem in theList
if nam of listItem is theNam then copy (email of listItem) to the end of retval
end repeat
return retval
end searchListforNam
Btw: I think you should avoid reserved words (‘text’, ‘name’) as your record’s keys.