How do you return a list of all the properties in a script object?

How do you return a list of all the properties in a script object?
I’ve tried “return my properties” and “get properties of me”,
but I always get a record of the script editor application’s properties.
I need to get a list of the custom properties that I declared in the
script object.

Also, is there a way to return the properties from a record,
kind of like this:
set x to {firstProperty:“”, secondProperty:1}
return properties of x – this doesn’t work.

For records it can be done with AppleScriptObjC:

use AppleScript version "2.4"
use framework "foundation"

property NSDictionary : class "NSDictionary"

set theRecord to NSDictionary's dictionaryWithDictionary:{firstname:"John", lastname:"Smith"}
theRecord's allKeys() as list
  1. The property properties, provided by developed objects is one record and not the list
  2. I see at least 3 ways to get all custom properties of embedded script, which is object as well:

Method 1: providing property properties by script itself for users:


script o
	property a : 1
	property b : "John"
	property x : {firstProperty:"", secondProperty:1}
	property properties : {a:a, b:b, x:x}
end script

set theProperties to properties of o -- using property Properties, provided by script itself

Method 2: returning all properties of o, using wrapping record in the calling script:


script o
	property a : 1
	property b : "John"
	property x : {firstProperty:"", secondProperty:1}
end script

set theProperties to {a:a, b:b, x:x} of o -- wrapping o's properties

Method 3: returning all properties of o, using [b]method |properties|/b provided by script object:


script o
	property a : 1
	property b : "John"
	property x : {firstProperty:"", secondProperty:1}
	on |properties|()
		return {a:a, b:b, x:x}
	end |properties|
end script

set theProperties to |properties|() of o -- using o's method

NOTE: The method 2) is more universal, because you can use it with external scripts as well and you want avoid editing the external script. It is enough to know key labels of external script.
The method 3) I see as the best of all, because it follows Cocoa approach to build the object properties and Cocoa approach is the safest approach.

Now, returning separate properties and summary |properties| of script object as 1 record (as implemented by professional applications):


script o
	property a : 1
	property b : "John"
	property x : {firstProperty:"", secondProperty:1}
	on |properties|()
		return {a:a, b:b, x:x}
	end |properties|
end script

set theProperties to {a:o's a, b:o's b, x:o's x, |properties|:o's |properties|()}

I want end up here with script returning main properties and custom properties together:


script o
	property a : 1
	property b : "John"
	property x : {firstProperty:"", secondProperty:1}
	on |properties|()
		return {a:a, b:b, x:x}
	end |properties|
end script

-- return main and custom properties of script object together
tell o to set allProperties to (properties & |properties|())