• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting Individual Metadata Items with ASObjC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting Individual Metadata Items with ASObjC


  • Subject: Getting Individual Metadata Items with ASObjC
  • From: Christopher Stone <email@hidden>
  • Date: Fri, 10 Jun 2016 04:20:03 -0500

Hey Folks,

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.

--
Take Care,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting Individual Metadata Items with ASObjC
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Best Method to Filter Lists?
  • Next by Date: Re: Best Method to Filter Lists?
  • Previous by thread: Re: Best Method to Filter Lists?
  • Next by thread: Re: Getting Individual Metadata Items with ASObjC
  • Index(es):
    • Date
    • Thread