Le 2015/11/16 à 18:21, Christopher Stone < email@hidden> a écrit :
On Nov 16, 2015, at 08:17, S. J. Cunningham < email@hidden> wrote: I have a handler to which I would like to pass a variable number of arguments. I am using a record to pass the arguments and then checking in the handler whether or not a specific field exists so I can skip it if it doesn't. ______________________________________________________________________
Hey Steve,
The hackish way to handle that:
set theRecord to {Field_1:"Field 1", Field_2:"Field 2"}
try theRecord / 0 on error eMsg set AppleScript's text item delimiters to {"{", "}"} set checkRecord to text item 2 of eMsg end try
set AppleScript's text item delimiters to ":"
set fieldName to text item 1 of checkRecord set s to fieldName & " of {" & checkRecord & "}" run script s
I believe there's an ASObjC method to extract the keys directly.
Maybe this enhanced version may help.
set theRecord to {Field_1:"Field 1", Field_3:"Field 3"}
try theRecord / 0 on error eMsg log eMsg set AppleScript's text item delimiters to {"{", "}"} set checkRecord to text item 2 of eMsg end try log checkRecord set AppleScript's text item delimiters to {":", ", "} set fieldsNames to {} set fieldsValues to {} set i to 1 repeat try set fieldName to text item i of checkRecord set end of fieldsNames to fieldName set s to fieldName & " of {" & checkRecord & "}" set end of fieldsValues to run script s set i to i + 2 on error exit repeat end try end repeat log fieldsNames (*Field_1, Field_3*) log fieldsValues (*Field 1, Field 3*)
As you see, it return the list of fieldsNames available in the record and a list of their values.
Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) lundi 16 novembre 2015 21:25:10
|