I know for a record I can get its custom metadata via
set theCMD to custom metadata of theRecord
theCMD will only contain keys for fields which have a non-default value.
How can I find out via Applescript all available fields like they are listed in Preferences -> Data?
The first script in this post lists them all in an AppleScript
choose from list. Clicking copies one meta data identifier at a time for pasting into a script.
Should be easy to change the script to do what you want.
If I understand the post correctly it is the first script that collects the metadata fields, and in order to do so it needs to read the metadata plist file, right?