How to parse AppleScript records with NSAppleScriptMBS?

How do I put an AppleScript record into a Xojo dictionary? The “seld” - of course - doesn
t word because the record isn’t an array. What do I need to use instead?

dim source as string = "set theList to {test:""mehr test""}"
dim n as new NSAppleScriptMBS(source)
dim d as Dictionary
dim result as NSAppleEventDescriptorMBS = n.execute(d)

if d<>nil then
  MsgBox d.Value(NSAppleScriptMBS.NSAppleScriptErrorMessage)
  'MsgBox result.description
  dim count as integer = result.numberOfItems
  dim names() as string
  for i as integer = 1 to count
    dim item as NSAppleEventDescriptorMBS = result.descriptorAtIndex(i)
    dim value as NSAppleEventDescriptorMBS = item.descriptorForKeyword("seld")
    list.addrow value.stringValue
end if

did you inspect value, what that is?

value is nil. I can see something in the item.description:

And I need the key for the dictionary, too.

here you go:

Dim source As String = "set theList to {test:""mehr test""}"
Dim n As New NSAppleScriptMBS(source)
Dim d As Dictionary
Dim result As NSAppleEventDescriptorMBS = n.execute(d)

If d<>Nil Then
  MsgBox d.Value(NSAppleScriptMBS.NSAppleScriptErrorMessage)
  Dim count As Integer = result.numberOfItems
  Dim names() As String
  For i As Integer = 1 To count
    Dim item As NSAppleEventDescriptorMBS = result.descriptorAtIndex(i)
    Dim nu As Integer = item.numberOfItems
    Dim p1 As NSAppleEventDescriptorMBS = item.descriptorAtIndex(1)
    Dim p2 As NSAppleEventDescriptorMBS = item.descriptorAtIndex(2)
    Dim t1 As String = p1.stringValue
    Dim t2 As String = p2.stringValue
    List.AddRow t1+": "+t2
End If

so item is the record and descriptorAtIndex(1) and descriptorAtIndex(2) give you the values.

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.