How do I trim first and last few seconds of a mp4 using AppleScript?
I'm using Mac 10.13.3. I want to trim the first second and the last two seconds from my mp4 (movie). I tried writing an Applescript like so
trim output.mp4 1 from (0*60 + 1) to (32*60 +38)
but when I try and save it, I get the error
A identifier can’t go after this identifier.
Could someone provide some guidance on how to correct my script? When I try and trim using the QuickTime GUI, I find I can't move the trim bars by just a second or two with my mouse (it seems to move in large increments), otherwise I'd use that route.
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 & 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.