Cannot get the correct group name of user owned items.

I need to get the current group name of user owned items items and if “admin”, change to “staff”.
I thought that this will do it. It does not.

tell application "Finder"
	set mySelection to selection as alias list
	set theItem to item 1 of mySelection
	set item_group to group of theItem
	if item_group is "admin" then set group of theItem to "staff"
end tell

It fails because the command

set item_group to group of theItem

returns “(unknown)” instead of “admin” (or “staff” for that matter) for any item whose owner is not “system”,
Note that, when the item’s owner is “system”, the command returns an acceptable “root”, while “Get info” shows “wheel”.

Checking the item’s properties reveals these results:

tell application "Finder"
	set mySelection to selection as alias list
	set theItem to item 1 of mySelection
	set item_properties to properties of theItem
	--For user owned items, the group is always "(unknown)" instead of  "staff" or "admin",
	--> {class:document file, name:"Ï€ test.scpt", index:1, displayed name:"Ï€ test.scpt", name extension:"scpt", extension hidden:false, container:folder "Desktop" of folder "chris" of folder "Users" of startup disk of application "Finder", disk:startup disk of application "Finder", ... owner:"chris", group:"(unknown)", owner privileges:read write, group privileges:read only, everyones privileges:read only, file type:"osas", creator type:"ToyS", stationery:false, product version:"", version:""}
	--For "system" owned items:
	--> {class:document file, name:"com.apple.alf.plist", index:19, displayed name:"com.apple.alf.plist", name extension:"plist", extension hidden:false, container:folder "Preferences" of folder "Library" of startup disk of application "Finder", disk:startup disk of application "Finder", ... owner:"system", group:"root", owner privileges:read write, group privileges:read only, everyones privileges:read only, file type:missing value, creator type:missing value, stationery:false, product version:"", version:""}
end tell

For any user owned items AS returns the group name as “(unknown)”, except from keyboard with right click + Get info.
Please,
is anything wrong above? Am I missing something?
If not,Where is this “(unknown)” coming from? Is it a bug?
is there any AS, ASObjC, shell or GUI way to get the actual group name of items owned by a user?
My OS version is 10.11.3.

Hi,

AppleScriptObjC returns the proper value

use framework "Foundation"

set fileGroupOwnerAccountName to current application's NSFileGroupOwnerAccountName

tell application "Finder"
	set mySelection to selection
	if mySelection is {} then return
	set theItem to POSIX path of (item 1 of mySelection as text)
end tell

set fileManager to current application's NSFileManager's defaultManager()
set attributes to fileManager's attributesOfItemAtPath:theItem |error|:(missing value)
set group to (attributes's objectForKey:fileGroupOwnerAccountName) as text

Hi Stefan,
Thank you. That works very nicely.

I wish Apple pays some real attention to AS. Ticking a list of new features without thorough quality control that all related items have been updated accordingly is deeply frustrating and doesn’t fit Apple’s reputation for attention to details.The Finder library is a mess; just look at labels and tags. And I still don’t know where this “(unknown)” group value is coming from or generated by. Anyway, down from my soapbox. Feeling better after my little rant.

Thank you again for the solution. I make it a handler and add it to my library.

Best regards,
Chris