Any way to get metadata out of a file with Applescript?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

So first of all Hazel absolutely rocks, have a pretty great setup of rules now that … well, automates some things I used to do manually. :P

I've set it up now to send me an iMessage when Hazel adds a file to my iTunes, but I've just been using theFile in the Applescript and it occurred to me that since the file has a lot of metadata it might be better to use that in the text message instead of the filename.

Been searching online, tried exiftool but that didn't seem to be able to get the metadata I wanted out of the m4v file. Tried AtomicParsley but it chokes on larger files.

So anybody here that knows any way of getting metadata out of a m4v container using Applescript or a shell script/command?
cstromme
 
Posts: 6
Joined: Wed Mar 09, 2011 3:20 pm

First, run mdls in terminal to find the name of the attribute that you're looking for:

Code: Select all
mdls /Users/andrewfreyer/myFileForHazelToMove.txt


You'll see all of the kMDItem_____ medadata element names. Find the one you want, and declare it with -n kMDItemPhysicalSize.

Code: Select all
mdls -n MDItemPhysicalSize /Users/andrewfreyer/myFileForHazelToMove.txt


Now you'll see this printed:

kMDItemPhysicalSize = 9865600


I'd just awk the third element like this:


Code: Select all
mdls -n MDItemPhysicalSize /Users/andrewfreyer/myFileForHazelToMove.txt | awk '{print $3}'


For applescript, wrap that line in a do shell script line and you're done!
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Thank you for that! :)

mdls doesn't seem to be able to access the media metadata though. As an example from a m4v file (with all the right metadata set and readable by iTunes) I get:

kMDItemFSContentChangeDate = 2012-10-29 22:46:46 +0000
kMDItemFSCreationDate = 2012-10-29 22:44:03 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = 0
kMDItemFSLabel = 0
kMDItemFSName = "name of file.m4v"
kMDItemFSNodeCount = 868616882
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = (null)
kMDItemFSTypeCode = ""
cstromme
 
Posts: 6
Joined: Wed Mar 09, 2011 3:20 pm

If the only metadata you are seeing are kMDItemFS entries, that means that the file is not being imported by Spotlight. Check your Spotlight privacy settings to make sure that they are being indexed properly.
Mr_Noodle
Site Admin
 
Posts: 11877
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Oh, I have spotlight turned off on the server (where this is running). I want to access this shortly after Identify has set the metadata though, would spotlight be done indexing it that quickly?

EDIT: Indexed it now, but it doesn't seem to get all the tags like TV show.
cstromme
 
Posts: 6
Joined: Wed Mar 09, 2011 3:20 pm

Keep in mind that Spotlight attributes are more generalized so what you see as TV Show may be stored as a different attribute in Spotlight, since Spotlight has to handle a bunch of different file types. It may also be the case where Spotlight doesn't import certain fields in which case you'll need to find a better importer for those files.
Mr_Noodle
Site Admin
 
Posts: 11877
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support