Script to Auto Trim Front and Back of Video Files

Hi there. I found the following Applescript online and I am desperate to use it. I have over 1,000 video files that I need to trim the first 6 and last seconds of. I saved this Applescript as a script, but it has multiple errors. Admittedly, I do not have any real script knowledge. Can someone please review this and let me know how to get this going. I sincerely appreciate your help.

set secondsFromStart to 6
set secondsFromEnd to 6
set shortMoviesList to {}

set srcFolder to choose folder

tell application "Finder"
	set fileList to files of folder srcFolder
	repeat with f in fileList
		tell application "QuickTime Player"
			open f
			tell document 1
				-- Check to make sure we're not trimming more time than the movie contains
				set timeScale to timescale
				set trimmedTime to (timeScale * (secondsFromStart + secondsFromEnd))
				if trimmedTime is greater than duration then
					-- Not enough content to trim, add file name to a list
					set end of shortMoviesList to (the name of f as string) & return
				else
					-- We have enough content, proceed to trimming
					set selection start to (timeScale * secondsFromStart)
					set selection end to (duration - (timeScale * secondsFromEnd))
					trim
					save
				end if
				close
			end tell
		end tell
	end repeat
	if length of shortMoviesList is greater than 0 then
		tell application "Finder"
			-- bring Finder to front so dialog is not hidden
			activate
		end tell
		display dialog "The following movies could not be trimmed because they do not contain enough content: " & return & return & shortMoviesList with icon caution
	end if
end tell

I’m making progress.

OK, so I am making some progress. I am now using the code below. It is working…somewhat. The problems now are:

  • It wants to save it as a QuickTime Composition. I want to save it as an mp4.
  • It is prompting me to choose the save directory and name the file.

I would like it to run unprompted. Ideally, I’d like to save the trimmed files with the same name as the current file but in a subfolder of that directory. Thus, giving me a folder with the originals and a subfolder with the trimmed files. Any thoughts on how to do that?


set secondsFromStart to 3.5
set secondsFromEnd to 3.5
set srcFolder to choose folder

tell application "Finder"
	set fileList to files of folder srcFolder
	repeat with f in fileList
		tell application "QuickTime Player"
			open f
			delay (0.25)
			tell document 1
				trim from secondsFromStart to (duration - secondsFromEnd)
				save
				close
			end tell
		end tell
	end repeat
end tell