I've just consolidated some code I've used for years into a handler.
I need to write a more general one that let's me input the metadata names to be extracted, but that'll wait for another day.
------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2016/06/09 03:48 # dMod: 2016/06/10 04:08 # Appl: Miscellaneous # Task: Get kMDItemWhereFroms metadata from the selected file in the Finder # Libs: None # Osax: None # Tags: @Applescript, @Script, @Finder, @Shell, @Metadata, @WhereFroms -------------------------------------------------------------------------------------------
tell application "Finder" to set finderSelectionList to selection as alias list if length of finderSelectionList = 0 then error "No files were selected in the Finder!" set posixPath to POSIX path of (item 1 of finderSelectionList)
set whereFromsList to getFileWhereFromsUrlList(posixPath)
------------------------------------------------------------------------------------------- --ยป HANDLERS ------------------------------------------------------------------------------------------- on getFileWhereFromsUrlList(posixPath) set whereFromsInfo to do shell script "mdls -name kMDItemWhereFroms " & quoted form of posixPath set whereFromsURLs to fndUsing ("\"(.+)\"", "\\1", whereFromsInfo , true, true) of me end getFileWhereFromsUrlList -------------------------------------------------------------------------------------------
After I wrote this I spent quite a while trying to figure out how to do this with ASObjC.
I started with a script Shane Stanley wrote in 2014 to convert my File-Info script to ASObjC.
The relevant bit is this:
# Get the Spotlight metadata set theNSMetadataItem to current application's NSMetadataItem's alloc()'s initWithURL:anNSURL set theAtts to theNSMetadataItem's attributes() set theMetadata to theNSMetadataItem's valuesForAttributes:theAtts attsNSMutableDictionary's addEntriesFromDictionary:{SpotlightData:theMetadata}
But I can't figure out how to return one or more metadata keys instead the whole thing.
At the moment I'm specifically looking for kMDItemWhereFroms.
Is this possible?
TIA.
|