Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.6: Use AppleScript for precise trimming in QuickTime X' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Use AppleScript for precise trimming in QuickTime X
Authored by: mr. applescript on Mar 08, '10 01:42:52PM
This will segment the front movie to the Movies folder. Be aware that the export queue is threaded, so exports will happen simultaneously (not necessarily a bad thing) unless you add a long delay between repeat loops. Enjoy!
property segment_length : (60 * 1)

tell application "QuickTime Player"
	if not (exists document 1) then error number -128
		display dialog "Enter the base name for the export movie file:" default answer ""
		set the base_name to the text returned of the result
		if the base_name is not "" then exit repeat
	end repeat
	set the movie_length to the duration of document 1
	set the segment_count to the (movie_length div segment_length)
	if (movie_length mod segment_length) is not 0 then set the segment_count to the segment_count + 1
	set start_time to 0
	repeat with i from 1 to the segment_count
		if i is the segment_count then
			set end_time to movie_length
			set end_time to start_time + segment_length
		end if
		set current time of document 1 to start_time
		trim document 1 from start_time to end_time
		set the target_file to ((path to movies folder as string) & base_name & "-" & (i as string) & ".mov")
		export document 1 in file target_file using settings preset "Computer" -- or "iPhone"
		delay 1 -- set to large number of seconds if you don't want the exports to queue
		my reset_movie()
		set start_time to end_time
	end repeat
	set current time of document 1 to 0
end tell

on reset_movie()
	tell application "System Events"
		tell process "QuickTime Player"
			keystroke "z" using command down
		end tell
	end tell
	delay 2
end reset_movie
Edited on Mar 08, '10 01:53:50PM by mr. applescript

[ Reply to This | # ]
10.6: Use AppleScript for precise trimming in QuickTime X
Authored by: philostein on Mar 08, '10 09:13:40PM
Hi, nice tips guys. I had trouble running mr. applescript's script - the time markers work well, but I got 5 identical movies. Perhaps keystroking 'z' using System Events is causing a problem? I've taken the liberty of adjusting the script so it closes and opens Document 1 instead:
mr applescript's QuickTime Player script PhilHints branch.scpt
QuickTime Player occasionally fails to complete the export process though.

I export movies linearly by using this code:

try -- Make sure file exists first
tell application "System Events" to physical size of file target_file
exit repeat
on error a number b
beep 1
end try
end repeat

repeat -- File only has physical size when completed
tell application "System Events" to set _size to physical size of file target_file
if _size ≠ 0 then exit repeat
delay 2
end repeat

Exports only have physical size after the export is complete.

I've incorporated the above code into the new script.
Cheers, PhilHints

[ Reply to This | # ]