How do I trim first and last few seconds of a mp4 using AppleScript?
tell application "QuickTime Player"
    set d to duration of document 1
    trim document 1 from 1 to (round d - 2)
end tell


Changes from above are highlighted bold.

If the file you want isn't open already, you need to open it with the ‘open’ function.


tell application "QuickTime Player"
    set doc to open alias "Mac SSD:Users:path:to:your:file"
    set d to duration of doc
    trim doc from 1 to (round d - 2)
end tell


These scripts perform the trim but don't save the file back automatically. You'll need to call ‘save’ if you want to save your changes, or use the GUI with your opened document.


You need to tell the application that provides the trim operation. Wrap your trim operation in a ‘tell application’ block, which in this case is to tell QuickTime Player.
The trim operation takes a document and start &amp; end points. The document is not a file name, but a document open in QuickTime Player. document 1 refers to the first document open.


Rather than hardcoded start and end points, you can get the duration from the video and take 2 seconds off the end to be used as the end point. This is what the d variable is used for in the code above.