Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript QuickTime Error

I'm trying to trim 7 seconds from the beginning of a folder full of .mov files using the script below, but I get an error that the script can't get the duration of the movie. I've tried everything to no avail. What's wrong with this script?


set srcFolder to choose folder


tell application "Finder"

set fileList to files of foldersrcFolder

repeat with f in fileList

tell application "QuickTime Player"


openf

set startTrim to 7

set endTrim to duration of f


trimffromstartTrimtoendTrim


save


close

end tell

end repeat

end tell

Mac mini, macOS High Sierra (10.13)

Posted on Nov 11, 2017 10:17 AM

Reply
Question marked as Best reply

Posted on Nov 13, 2017 6:56 AM

Hi Richard,


When QuickTime trims the file, it creates an unsaved copy in an untitled window, and leaves the original untouched. Saving this untitled window via a script has given me all sorts of grief - it has to be exported. So to give the impression of trimming, saving and closing, you have to do something like this:


set srcFolder to choose folder

set fileList to list foldersrcFolder without invisibles

set folder_string to srcFolder as text

repeat with f in fileList

set file_path to folder_string & f

tell application "QuickTime Player"


activate


openfilefile_path

set startTrim to 7

set endTrim to duration of document 1


trimdocument 1 fromstartTrimtoendTrim

tell application "Finder" to delete file file_path


exportdocument 1 infile_pathusing settings preset "720p"


closedocument 1 without saving

end tell

end repeat

This opens the files, trims them, uses Finder to delete the original, exports the untitled document into the folder with the same name as the original, then closes the still-open "untitled" document without saving. You have to use a settings preset when you export. I've arbitrarily used 720p, the options are here:

User uploaded file


I'm not sure if this is the only, or even the best, way of doing it. You may end up with an export dialog still working away for a few seconds after the last movie has closed. It does not preserve the file creation dates of the original movies. But I think it does what you want to do.


I strongly suggest that you test the above script on copies - do not use original movies that you value or cherish, or that belong to a client. Make absolutely sure that the script does what you want it to do before you incorporate it into a workflow. I will not be held responsible if you lose data as a result of running it.


Cheers,


H

7 replies
Question marked as Best reply

Nov 13, 2017 6:56 AM in response to Richard Groff2

Hi Richard,


When QuickTime trims the file, it creates an unsaved copy in an untitled window, and leaves the original untouched. Saving this untitled window via a script has given me all sorts of grief - it has to be exported. So to give the impression of trimming, saving and closing, you have to do something like this:


set srcFolder to choose folder

set fileList to list foldersrcFolder without invisibles

set folder_string to srcFolder as text

repeat with f in fileList

set file_path to folder_string & f

tell application "QuickTime Player"


activate


openfilefile_path

set startTrim to 7

set endTrim to duration of document 1


trimdocument 1 fromstartTrimtoendTrim

tell application "Finder" to delete file file_path


exportdocument 1 infile_pathusing settings preset "720p"


closedocument 1 without saving

end tell

end repeat

This opens the files, trims them, uses Finder to delete the original, exports the untitled document into the folder with the same name as the original, then closes the still-open "untitled" document without saving. You have to use a settings preset when you export. I've arbitrarily used 720p, the options are here:

User uploaded file


I'm not sure if this is the only, or even the best, way of doing it. You may end up with an export dialog still working away for a few seconds after the last movie has closed. It does not preserve the file creation dates of the original movies. But I think it does what you want to do.


I strongly suggest that you test the above script on copies - do not use original movies that you value or cherish, or that belong to a client. Make absolutely sure that the script does what you want it to do before you incorporate it into a workflow. I will not be held responsible if you lose data as a result of running it.


Cheers,


H

Nov 13, 2017 8:17 AM in response to HD

Thank you! This DOES work after all. I should have run it without making any changes first. I replaced "720p" with "Audio Only" and it was exporting each file as "m4a" instead of "mov". For some reason, that was the problem. Without going into a long story, these were old files from an online old-time radio website I used to manage. No video, just audio. So now that they have been successfully trimmed I can use another app to batch-convert them to mp3s.


Thanks once again HD!!!

Applescript QuickTime Error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.