• 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: coerce record to string - does this work in other System languages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: coerce record to string - does this work in other System languages?


  • Subject: Re: coerce record to string - does this work in other System languages?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 25 Mar 2010 19:11:17 -0400

On Thu, Mar 25, 2010 at 6:54 PM, Luther Fuller <email@hidden> wrote:
> The problem, now, is to get the value of a named record item.

My pluck handler from the other thread does that, but across a list of records:

item 1 of pluck("a", { {a:1, b:2, c:3} })
1

> I tried using 'run script ...', but this does not work.

It does, but you have to be tricky because you can't pass parameters
to a 'run script', nor can the code inside the string access variables
or properties from the surrounding context.

The trick, which I believe I learned from has, is to use 'run script'
to create a new script object containing a handler that takes a
parameter, where the body of the handler incorporates the dynamic
code.  Then, back in normal non-tricky code, you just invoke that
handler with the target object:

on getKey(someRecord, keyName)
    set getter to (run script "script" & return & "on open(aRec)" & return & "re
turn " & keyName & " of aRec" & return & "end open" & return & "end script")
    tell getter to open(someRecord)
end getKey

getKey({a:1, b:2, c:3}, "a") -- returns "1"


--
Mark J. Reed <email@hidden>
 _______________________________________________
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

  • Follow-Ups:
    • Re: coerce record to string - does this work in other System languages?
      • From: "Mark J. Reed" <email@hidden>
References: 
 >coerce record to string - does this work in other System languages? (From: Skeeve <email@hidden>)
 >Re: coerce record to string - does this work in other System languages? (From: Luther Fuller <email@hidden>)

  • Prev by Date: Re: old script fails AND BUG in Smile 3.5.2 (build 609)
  • Next by Date: Re: old script fails AND BUG in Smile 3.5.2 (build 609)
  • Previous by thread: Re: coerce record to string - does this work in other System languages?
  • Next by thread: Re: coerce record to string - does this work in other System languages?
  • Index(es):
    • Date
    • Thread