Wednesday, June 3, 2020

#1 2020-02-21 02:52:18 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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:

Applescript:


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?


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#2 2020-02-21 04:42:24 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

Re: Getting extended file info (AsObjC)

Try using NSMetadataItem instead:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2020-02-21 10:24:43 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Getting extended file info (AsObjC)

This is just what I need. Many thanks.


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)