I am trying to pass a variable into an associative array but instead of the value of the variable I am passing the name of the variable.
set nameOfVariable to "random name"
set valueOfVariable to "random value" -- both variables (name and value) are constantly changing
set newArray {nameOfVariable:valueOfVariable}
-- this returns the following string {nameOfVariable:"random value"}
-- how do I make it to return {"random name":"random value"} ??
Regular AppleScript doesn’t have anything like that (a record’s key name must be declared at compile time), but AppleScriptObjC can be used to access the Cocoa API, for example:
Note that in an AppleScript record, to use spaces and other illegal variable characters, the key name can be enclosed in pipes, for example
|random name|.