If the keywords happen to be saved as Spotlight Comments, then you can access them with the following AppleScript code:
set imgfilepath to "Macintosh HD:Users:martin:Desktop:test.jpg"
tell application "Finder"
set filecomment to comment of (imgfilepath as alias)
end tell
I’ve been playing around with moving descriptive data to/from the Spotlight comment but I need access to the extended information that appears in the “More Info” section of a file’s information window.
As an example; select an MP3 file that has some information in the metatags and get the file information on it. You’ll see that fields such as “Artist”, “Album” etc. only appear in the “More Info” section. And you don’t seem to be able to read/write this via AS - but the information is clearly there as it appears in the information window. However, if you import/add the file to iTunes, for example, you can then query the metatags using, for example;
tell appliction "iTunes"
artist of track 1 of playlist 1
end tell
Unnecessary detail but might put the problem in context;
The bigger picture is I’m struggling with getting Soundtrack Pro to get proper search results from my SFX library. I’ve put descriptions in the Spotlight comment field for each file and I’ve also set the “Comment” tag for each file in iTunes. Doing a Spotlight search always yields the results I want but Soundtrack Pro’s own media browser/searcher is hit and miss. I’m trying to track down the reason for this. I’m wondering if it’s because Soundtrack isn’t able to read the Spotlight comments or the metadata contained in the files. Therefore I’m trying to write a tool to pull the data around to see if it helps Soundtrack.
Neil:
The type of data you’re looking at is deeper than Spotlight Comments. I am not on a Leopard machine (and there are sufficient changes between Tiger and Leopard concerning metadata) but you are most likely looking at kMDItemKeywords. Here’s a little snippet to let you see them if they exist.
set chosenFile to (quoted form of POSIX path of (choose file))
do shell script "mdls -name kMDItemKeywords " & chosenFile
Note, you can remove ‘-name kMDItemKeywords’ or replace the kMD with another value. This can also be easily accomplished by typing 'mdls ’ in Terminal and dropping your file on the Terminal window.
As far as setting these attributes, there is no easy way as far as I know.