I have this system, consisting of a bunch of different applications/scripts (website, database, Max/MSP) including an applescript to trim video’s to a certain size. But somehow, some video’s didn’t get trimmed and remained their full length. I found out the problem is caused by the applescript. Take a look at the following lines (which is just a small part of the script, but the part with the problem):
tell application "QuickTime Player" open item 1 of argv select at (item 2 of argv) to (item 3 of argv) trim (...)
AKA open the file specified in the 1st parameter, select the part between the 2nd and 3rd parameters (which are miliseconds, taking into account the timescale of the movie (600)) and trim the movie to the selected part. But as said, some video’s don’t get trimmed.
I found out what the problem is; when you run the script the file opens, but it seems some files take a little time getting fully loaded; you can see the time-line getting filled from left to right. But the trim script will be executed immediately after opening the file; causing files which are not fully loaded yet to ignore the trim command and stay at their full length (you’ll just see the selection in the time-line disappear).
I’m now using a simple timeout between the opening and trimming of the file:
tell application "QuickTime Player" open item 1 of argv delay 3 select at (item 2 of argv) to (item 3 of argv) trim (...)
But ofcourse, this isn’t really good practice: 3 seconds can be way too much for some files, but could be too short for some others. Also, I need the script too execute as fast as possible; every second of delay is a second too much.
Doesn’t the Quicktime Player have some sort of onLoadFinished event? Or does anyone know a different way to see if the file is fully loaded, and then execute the trimming script?