Is there any way to get the duration of a video file and save it as a variable in KM?
I am appending their duration to video file names — easily done with, e.g.: Name Mangler — as part of a larger macro involving renaming each movie file's parent folder.
I checked the drop-down list of file attributes in the KM Action "Get File Attribute", but I don't find it there, nor is it listed on that Action's Help page among the attributes accessible.
This AppleScript returns the duration of a selected video in seconds.
set macPath to (choose file) as text
tell application "System Events"
set ts to time scale of movie file macPath
set dur to duration of movie file macPath
set movieTime to dur / ts
end tell
I am yet green behind the horns ... I figured out how to execute this and pass the result to additional Actions, but I don't yet know how to make it work on multiple files selected (in, in my case, Path Finder, using Chris' Get Items AppleScript).
Below is what I have so far for appending the duration in mmm'ss format to a movie file's name. Getting the duration and appending it works — though I'd be happy for suggestions regarding what I've done there.
How do I send the Paths to the AppleScript that gets the movie duration? I tried changing "choose file" to "Path" in the first line of the AppleScript, but it did not work.
Minor:
What is the syntax for the math function MOD? I found it in the KM 6 Help, but I didn't manage to make it work.
What units are time scale and duration in the AppleScript. It puzzles me that dur / ts yields seconds.
To answer my own question I'm now using exiftool to save the output to a variable where I can use regex to extract the data I want thus making the AppleScript I enquired about redundant.
I found exiftool better than mediainfo for the job because mediainfo doesn't seem to include the seconds if the video is over an hour whereas exiftool does.
Users must install exiftool directly or via MacPorts or Homebrew – it does not come stock on macOS.