Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Assuming I have an MP4/M4V file of a TV show. The file has the necessary metadata so it can be imported into iTunes and you'll see the all the relevant information. Using AppleScript, one can extract that information using iTunes.

How would one obtain the show name, season and episode of that file using AppleScript without having to import it into iTunes first?

In essence, I have an incoming folder where I can "drop" my movies and tv shows and I'd like to use the script to organize the files without human intervention so that files will follow a naming convention so they are easier to find in the future.

share|improve this question
up vote 0 down vote accepted

Exiftool is a great tool to extract metadata. This script should point you in the right direction.

set thePath to POSIX path of (path to documents folder) & "exifdata"
do shell script "mkdir -p " & quoted form of POSIX path of thePath

tell application "Finder" to set theSelection to selection
repeat with anItem in theSelection
    set theLocation to POSIX path of (anItem as text)
    set {name:fileName, name extension:nameExtension} to anItem
    set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
    set destLocation to quoted form of (thePath & "/" & baseName & ".txt")
    do shell script "exiftool -a " & quoted form of theLocation & " >" & destLocation
    do shell script "open " & destLocation
end repeat

Or another approach is :

set myFile to quoted form of (POSIX path of (path to desktop as text) & "movie.mp4")

set xxx to every paragraph of (do shell script "mdls " & myFile)
share|improve this answer
mdls doesn't work for TV Shows. exiftool works great. – bloudraak Aug 27 '12 at 7:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.