Retrieve only the first item of a non-string object which has multiple instances.
/* This represents an object that is not a string and has multiple instances.
These line retrieve them all.*/
hardware ids of active devices
unique values of hardware ids of active devices
/* There seems to be no built-in way to retrieve just the first instance of the object.
This does it! It probably doesn't work for all objects, but it worked in this case. */
tuple string item 0 of concatenation ", " of unique values of it of hardware ids of active devices
/* Here is the latter used in a full expression that builds CSV output of device information.
The "%22" represents the ASCII code for a double quote as a method of escaping it to use it as a literal string. */
("%22" & (if exists manufacturer of it then manufacturer of it & "%22,%22" else "[no manufacturer]%22,%22") & (if exists friendly name of it then friendly name of it & "%22,%22" else if exists description of it then description of it & "%22,%22" else "[no name]%22,%22") & (if exists class of it then class of it & "%22,%22" else "[no class]%22,%22") & (if exists hardware ids of it then tuple string item 0 of concatenation ", " of unique values of it of hardware ids of it else "[no hardware id]") & "%22") of active devices