Getting extended file info (AsObjC)

Hi, all.

In an attempt to find out the origin of the file (tested with .doc file), I wrote the following code:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set aFile to choose file
set fileManager to a reference to current application's NSFileManager's defaultManager()

set aDictionary to fileManager's attributesOfItemAtPath:(POSIX path of aFile) |error|:(missing value)
set extendedAttributes to aDictionary's NSFileExtendedAttributes
set whereFrom to extendedAttributes's |com.apple.metadata:kMDItemWhereFroms|
set whereFrom to my ASDataFromData:whereFrom

on ASDataFromData:theData
	set theCode to current application's NSHFSTypeCodeFromFileType("'rdat'")
	return (current application's NSAppleEventDescriptor's descriptorWithDescriptorType:theCode |data|:theData) as data
end ASDataFromData:

As you see, I get the result as NSData, then as raw data. But how can I get this extended info in the human-readable form?

Try using NSMetadataItem instead:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set aFile to choose file
set targetURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of aFile)
set mdItem to current application's NSMetadataItem's alloc()'s initWithURL:targetURL
set theKeys to (mdItem's attributes())
if theKeys's containsObject:"kMDItemWhereFroms" then
	return (mdItem's valueForAttribute:"kMDItemWhereFroms") as list
else
	error "File has on kMDItemWhereFroms values"
end if

This is just what I need. Many thanks.