• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Coercion of list to record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coercion of list to record


  • Subject: Re: Coercion of list to record
  • From: Ed Stockly <email@hidden>
  • Date: Thu, 7 Feb 2008 07:33:42 -0800


I wish to create a list of records at run-time.


May I point out, however, that since the record labels are coming from Excel, how do you know what they are so you can refer to them in your
script? Either you just know because they're static, in which case there are other ways to create the record using normal keys, or you
don't know because they're dynamic, in which case you need to do the same string-to-key translation whenever you want a value, which is going to suck.



Depending on how your script and data is structured, the variation below my work for you. Rather than have the hander return the full record and values each time you call it for each set of data, once you've learned what your record labels are, just call the handler once to create a record template, which you would then copy to a variable for each value set.


In other words, the only thing you really need the run script for is to set the record labels. Do that just once and add the data as needed. (Of course, if all your record labels are unique this approach wouldn't work.)

on CreatRecordLabels(labels)
  set emptyRecord to {}
  repeat with thisLabel in labels
    set end of emptyRecord to (thisLabel as string) & ":\"\""
  end repeat
  set oldDelims to AppleScript's text item delimiters
  set AppleScript's text item delimiters to {","}
  set emptyRecord to ("{" & emptyRecord as string) & "}"
  set AppleScript's text item delimiters to oldDelims
  return run script emptyRecord
end CreatRecordLabels

set nameAgeRecord to CreatRecordLabels({"name", "age"})
--{name:"", age:""}

repeat with thisValue in myData
  copy ageNameRecord to thisRecord
  set thisRecord's name to item 1 of thisValue
  set thisRecord's age to item 2 of thisValue
  set the end of allMyRecords to thisRecords
end repeat

HTH,

ES

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Prev by Date: Re: Coercion of list to record
  • Next by Date: Re: Coercion of list to record
  • Previous by thread: Re: Coercion of list to record
  • Next by thread: Re: Coercion of list to record
  • Index(es):
    • Date
    • Thread