using Applescript to retrieve movie file duration via Finder properties

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-06-06T20:30:54Z Indexed on 2010/06/06 23:12 UTC
Read the original article Hit count: 380

Filed under:
|
|
|

When using Get Info on movie files in the Finder, I've noticed that many movie files have an accessible "Duration" property under the More Info tab. Is there an easy way to access this data using Applescript? I've tried lines like "set theTime to (duration of aFile)", but it doesn't seem to be as simple as that.

Ideally I'd like to access the movie duration via the Finder properties without having to actually open the file in QuickTime. Is this possible?

Edit:

I seem to have figured this out... you need to use the "System Events" application, specifically the Movie File Suite of commands (and, importantly, you need to set the movie variable as a string, rather than an alias):

set theMovie to (choose file with prompt "Select a movie file:") as string

tell application "System Events"
    set theName to name of movie file theMovie
    set theDuration to (duration of contents of movie file theMovie) / (time scale of contents of movie file theMovie)
end tell

© Stack Overflow or respective owner

Related posts about applescript

Related posts about quicktime