On the Go Lists of Records

Hello everyone!!!

I’m not really new to AppleScript but I am sometimes bad at debugging scripts.
I’m making a not-to-complex AppleScript Studio app. It involves getting a list of records of Mac models the user owns as nicknames and other info.

This is what I have so far storing 2 macs in a list.


set theMacs to {}
set theName to text returned of (display dialog "Nickname?" default answer "") --Let's say we typed in 'iMac'
set theInfo to text returned of (display dialog "Other Info?" default answer "") --I have a reason for this to be required; Let's say we typed 'Old'
set theMacs to theMacs & {nickname:theName, info:theInfo} as record
set theName to text returned of (display dialog "Nickname?" default answer "") --Let's say we typed in 'MacBook'
set theInfo to text returned of (display dialog "Other Info?" default answer "") --Let's say we typed in 'New'
set theMacs to theMacs & {nickname:theName, info:theInfo} as record

This script would then return {nickname: “iMac”, info: “Old”} instead of the whole thing which should be {{nickname: “iMac”, info: “Old”}, {nickname: “MacBook”, info: “New”}}

What in the world am I doing wrong?

Several things. When you concatinate a record, it adds terms to the record, it doesn’t make a list of them:

set X to {firstName:"Adam", initial:"C"} -- as record not needed; the colon does it.
set Y to {lastName:"Bell"}
set Whole to X & Y --> {firstName:"Adam", initial:"C", lastName:"Bell"}

You start with a list definition, but your “as record” coerces it to a record.

You use the same names for the record categories.

set X to {name:"Adam", initial:"C"}
set Y to {name:"Bell"}
set Whole to X & Y --> {name:"Adam", initial:"C"} --> note, no name:"Bell" is added

Some alternatives:


set NN1 to text returned of (display dialog "Nickname?" default answer "") --Let's say we typed in 'iMac'
set Info1 to text returned of (display dialog "Other Info?" default answer "") --I have a reason for this to be required; Let's say we typed 'Old'
set Mach1 to {M1Name:NN1, M1Info:Info1}
set NN2 to text returned of (display dialog "Nickname?" default answer "") --Let's say we typed in 'MacBook'
set Info2 to text returned of (display dialog "Other Info?" default answer "") --Let's say we typed in 'New'
set Mach2 to {M2Name:NN2, M2Info:Info2}

set the theMacs to Mach1 & Mach2 --> {M1Name:"iMac", M1Info:"old", M2Name:"PowerBook", M2Info:"new"}

-- Or

set theMacs2 to {Mach1}
set end of theMacs2 to Mach2
theMacs2 --< {{M1Name:"iMac", M1Info:"old"}, {M2Name:"PowerBook", M2Info:"new"}}

Wow Thanks!