Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Export seems to be broken. I tested on OS X 10.9.2 with Quicktime 10.3 (727.3) and there's no error but the export doesn't happen. Trouble is I can't remember on which version of OS X it used to work. Must have been 10.9 or 10.9.1. The only suggestion I can give is to look for another program that is scriptable and can trim to do the job. Perhaps iMovie or FCP. I'm just guessing here because I haven't really looked at those programs. Or you can still use Quicktime 7 on Mavericks according to Apple. You can also try GUI scripting Quicktime X.

Note : It's also broke on Yosemite
 

VideoBeagle

macrumors 6502a
Aug 17, 2010
822
18
App Q&A testing by request.
Thanks for checking on that.

Well first I tried going with quicktime 7 and I was able to piece together the meat of the code despite as always Apple's suck documentation.

Code:
tell application "QuickTime Player 7"
	activate
	set endd to duration of document 1
	select document at 5300 to endd
	trim document 1
I have no idea what the "5300" is. It's not the frame, and it's not seconds, but it's equivalent to a bit less than 8.5 seconds.

But when I tried to add in export commands, or put this into the automated code that Kryten2 wrote, it gives me errors and roadblocks.

Code:
set srcFolder to choose folder
set dstFolder to choose folder with prompt "Choose the destination folder for the trimmed files." default location srcFolder

tell application "Finder"
	set fileList to files of folder srcFolder
end tell


repeat with f in fileList
	tell application "QuickTime Player 7"
		open f
		set documentName to name of f
		set endd to duration of document 1
		delay (0.25)
		tell document 1
			
			select document at 5300 to duration
			trim
			export of file ((dstFolder as text) & documentName) using settings preset "Sound to AIFF"
			(*			
			close saving no
			*)
		end tell
	end tell
end repeat

This opens the movie in Quicktime Player X rather than 7, but then 7 tries to do the work and errors out.

SO I moved back to the Quicktime Player X original code, thinking maybe I could just have it save the trimmed file rather than export it. It's not ideal for actually learning ANYTHING but it would get what I want to get done, done.

Code:
			#export in file ((dstFolder as text) & documentName) using settings preset "480p..."
			save in file ((dstFolder as text) & documentName)
But, saving just generates a permissions error.
The document “Untitled 2” could not be saved as “test.mp4”. You don’t have permission.
To view or change permissions, select the item in the Finder and choose File > Get Info.
(Of course, changing the original file permissions did nothing).

I guess I'll try GUI scripting next...joy.
 

VideoBeagle

macrumors 6502a
Aug 17, 2010
822
18
App Q&A testing by request.
Well, found a workable, if not optimal solution with GUI scripting, using it to save the trimmed file with keystroke commands after failing to get the export menu options to work. (and then dumped the resulting files into MediaHuman Audio Converter for quick conversion).

Code:
set srcFolder to choose folder
set dstFolder to choose folder with prompt "Choose the destination folder for the trimmed files." default location srcFolder

tell application "Finder"
	set fileList to files of folder srcFolder
end tell


repeat with f in fileList
	tell application "QuickTime Player"
		open f
		set documentName to name of f
		set the clipboard to (text 1 thru ((offset of "." in documentName) - 1) of documentName)
		delay (0.25)
		tell document 1
			trim from 8.95 to duration
			tell application "System Events"
				tell process "QuickTime Player"
					keystroke "s" using command down
					keystroke "v" using command down
					delay 1
					keystroke return
					delay 3
					#click menu item "Save..." of menu "File" of menu bar 1
				end tell
			end tell
			
			close saving no
			
		end tell
	end tell
end repeat
beep 5
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Well, found a workable, if not optimal solution with GUI scripting, using it to save the trimmed file with keystroke commands after failing to get the export menu options to work. (and then dumped the resulting files into MediaHuman Audio Converter for quick conversion).


You can get the export menu options to work by using this :

Code:
tell application "System Events"
	tell process "QuickTime Player"
		click menu item "Audio Only…" of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
	end tell
end tell

You can wait while the Export Progress is showing with this :

Code:
repeat while (exists window "Export Progress")
end repeat
 

VideoBeagle

macrumors 6502a
Aug 17, 2010
822
18
App Q&A testing by request.
Cool! Good to know for the future!

(You should write a book! Or at least avoid being on a crashed star liner).

You can get the export menu options to work by using this :

Code:
tell application "System Events"
	tell process "QuickTime Player"
		click menu item "Audio Only…" of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
	end tell
end tell

You can wait while the Export Progress is showing with this :

Code:
repeat while (exists window "Export Progress")
end repeat

Did a Bug Report on the Export issue, quoting Kryten2 (bug # 17461845)
 
Last edited:

fedebarberan

macrumors newbie
Apr 22, 2018
1
0
Cordoba Capital
Hi all!

After 8 years, is this possible to do? I was pasting your codes an I was not lucky at all.

I want to trim a video file and save it in the same file, no export to duplicate the file.
Thanks in advance!
 

michaelpip

macrumors newbie
Jun 27, 2018
1
0
DC
Any luck here. I am trying to do that with several audio albums to create 30 or 45 second sample clips.

Hi all!

After 8 years, is this possible to do? I was pasting your codes an I was not lucky at all.

I want to trim a video file and save it in the same file, no export to duplicate the file.
Thanks in advance!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.