Saving a Quicktime Movie

Hi Everyone,

Long time no see! :wink: I’ve got this (nine year old) blog post that still gets some hits. It’s a tutorial on scheduling Quicktime Recordings with Automator. As Mac OS and QT have changed over time I’ve needed to tweak the guide to keep it functioning. That time has come again.

There are two automations at play: start a QT recording, end the recording. The new issue comes with ending the recording as QT used to automatically save the movie as soon as you stopped it. That no longer happens. Once the recording stops I need one more step to save the file.

So…I have developed a little bit of a workaround to get this functioning, but I would like to clean it up with an AppleScript Save As, if possible. When I’ve tried to save the file with a simple “save the font document” (or any other permutation of the same) I end up with a permission error. “The document “Untitled” could not be saved as “Movie.mov”. You don’t have permission” (I was trying to save it to the desktop.)

The stop/save script would look something like this:

tell application "QuickTime Player"
	try
		stop document 1 -- to stop capture
	end try
	delay 2
	save the front document in "/Users/UserName/Desktop/Movie.mov"
end tell

But with the permission error I strung together some other moves to get it going. I’m essentially using System Events to emulate keystrokes to get this done. In Automator I have a “Run AppleScript” action that stops the recording, then I have another Run AppleScript action that handles the saving, like this:

tell application "QuickTime Player"
	activate
end tell


tell application "System Events" to keystroke "w" using command down
delay 1
tell application "System Events" to keystroke "d" using command down
delay 1
tell application "System Events" to keystroke return

Keystroke W, tries to close the recording, Keystroke D pushes it to the Desktop, Keystroke return forces the save. So again, this does work alright. But part of me wants to do it a little more cleanly with a “Save As” instead.

Otherwise, I simply have the above action run, then an Automator Pause, then a Rename Finder Items action, then a “Move Finder Items” action.

I’m sure I’m missing something simple with the “Save As”.

Thanks for your time!

Hi.

Have you tried exporting instead?

set savePath to (path to desktop as text) & "Movie.mov"

tell application "QuickTime Player"
	try
		stop document 1 -- to stop capture
	end try
	delay 2
	
	export the front document in file savePath using settings preset "480p"
end tell

I haven’t tried it immediately after a recording, but it works to save pre-existing .mov documents from the player under other names. The possible ‘settings presets’ are listed in the player’s “Export As” menu, although it doesn’t seem to make any difference which one is specified!

Hi Nigel,

Thanks for the input. That does indeed seem to work, although it definitely imparts the expected compression into the saved movie.

I’m just experimenting with webcam recordings for now. But if I do a ‘normal’ save as my resulting movie is a 1280 x 720, Apple ProRes 422 file that is roughly 28MB. If I instead take the export path for the same file (set to 720p) the movie produced is a 1280 x 720 H.264 file that is roughly 3MB in size.

It would be nice to have the option to export/compress but also do a Save As to maintain as much quality as possible. Perhaps I’m just going to have to stick to my little “workaround”?

Cheers,
Kevin


tell application "QuickTime Player"
	activate
	try
		stop document 1 -- to stop capture
	end try
	delay 2
	close document 1 saving in "/Users/UserName/Desktop/Movie.mov" as POSIX file
end tell

Thank you for the input. Unfortunately though, this still triggers the permission problem that I alluded to earlier. It doesn’t save the file as expected.

OK. This saves the new recorded from camera document as QuickTime Player Movie Package on the desktop, then moves Movie Recording.mov to the desktop, then renames Movie Recording.mov as you want, then deletes the package.


set thePackagePath to POSIX path of (path to desktop) & "NewMovie.qtpxcomposition/"

tell application "QuickTime Player"
	activate
	stop document 1 -- to stop capture
	delay 2
	set thePackageFile to (thePackagePath as POSIX file)
	save document 1 in thePackageFile
	quit
end tell

set theMovie to POSIX file (thePackagePath & "Movie Recording.mov")
tell application "Finder"
	set theMovie to move theMovie to desktop
	set name of theMovie to "Movie.mov"
	delete thePackageFile
end tell

A QTPXCOMPOSITION file is an archive created by QuickTime, a video playback program bundled with macOS. It contains files that make up an unsaved recording created in QuickTime, which may include .MOV files for video recordings or .M4A files for audio recordings.

NOTE: Unsaved QuickTime Player Document.qtpxcomposition - The default name given to QTPXCOMPOSITION files that have not yet been named by the user. This is the typical name seen by users looking for a lost recording.

Thanks so much, this works great. I’ve been testing this by recording webcam movies, via Quicktime, so it’s all .mov files. In those instances it works just fine.

However, if I switch it up and try to run the same process on an audio recording, I get the Script Error: “Finder got an error: Handler can’t handle objects of this class” and points to this area, of this line:

move theAudio to (path to desktop)

tell application "Finder" to move theAudio to (path to desktop)

I tried changing the .mov references in the script to .aif and .m4a to no avail. Same issue. How could you correct this?

Thanks again!

For audio recording:


set thePackagePath to POSIX path of (path to desktop) & "NewAudio.qtpxcomposition/"

tell application "QuickTime Player"
	activate
	stop document 1 -- to stop capture
	delay 2
	set thePackageFile to (thePackagePath as POSIX file)
	save document 1 in thePackageFile
	quit
end tell

set theAudio to POSIX file (thePackagePath & "Audio Recording.m4a")
tell application "Finder"
	set theAudio to move theAudio to desktop
	set name of theAudio to "Audio.m4a"
	delete thePackageFile
end tell

Thanks for taking another swing at this. But I’m still getting that same error.

“Finder got an error: Handler can’t handle objects of this class.” And it locks onto this section:

move theAudio to (path to desktop)

tell application "Finder" to move theAudio to (path to desktop)

Does it run successfully on your end? What could we (I) be missing?

Thank you,
Kevin

I don’t know. Maybe you have already one audio file on desktop with name Audio.m4a. So, remove it, or give other name.

And provide here the screenshot with contents of your NewAudio.qtpxcomposition package, if you can.

Maybe, you entered my code manually and have some error. So, open my code as is from this site. It works for me fine. Only change 123 to your username

I’ve been making sure to clear the Desktop of any files that may conflict with saving/naming, so I don’t think it would be that.

Here’s the package contents of the “NewAudio.qtpxcomposition” file that gets built:

I’m opening the Scriplet from this page, then changing the “123” in the path to the proper name for my system. Not sure what else I could be missing.

The POSIX file - POSIX path back and forth dance is very cumbersome.

And the Finder has a desktop property

This is more efficient

set thePackagePath to (path to desktop as text) & "NewAudio.qtpxcomposition:"

tell application "QuickTime Player"
	activate
	stop document 1 -- to stop capture
	delay 2
	save document 1 in thePackagePath
	quit
end tell

set audioFile to thePackagePath & "Audio Recording.m4a"
tell application "Finder"
	set movedAudioFile to move file audioFile to desktop
	set name of movedAudioFile to "Audio.m4a"
	delete item thePackagePath
end tell

Thanks for your time and input, Stefan. I especially appreciate the effors to streamline the script too. But I’m hung up in the same familiar loops of errors it would seem.

Now I’m back to the “You don’t have permission” problem.

Well, from screenshot I see you need this code for audio recording:


set thePackagePath to POSIX path of (path to desktop) & "NewAudio.qtpxcomposition/"

tell application "QuickTime Player"
	activate
	stop document 1 -- to stop capture
	delay 2
	set thePackageFile to (thePackagePath as POSIX file)
	save document 1 in thePackageFile
	quit
end tell

set theAudio to POSIX file (thePackagePath & "Audio Recording.aifc")
tell application "Finder"
	set theAudio to move theAudio to desktop
	set name of theAudio to "Audio.aifc"
	delete thePackageFile
end tell

NOTE: Thanks to StefanK I improved my scripts above.

@kevincbrock

You have to add Script Editor (or the application running the script) to the applications which have Full Disk Access in System Preferences

@KniazidisR

You are still using POSIX file and POSIX paths. And the as alias coercion is redundant

You script, StefanK has 1 error - you are missing creating new file. So, it fails. As for as alias coercion , you are right, and I fixed my mistake.

@StefanK

I’m not sure what else I should change. In the ‘Security & Privacy’ section of the System Preferences I’ve included Script Editor, Quicktime (and already had Automator there) but I still get the “You don’t have permission” barricade. I’ve been running the script right in the Script Editor for now. The ‘mov’ version works, odd that the audio versions of the same is so much trickier.

Run my last script.

This iteration is working for me.

Once a recording is stopped, the mov file can be copied from ~/Library/Containers/com.apple.QuickTimePlayerX/Data/Library/Autosave Information/
For a screen recording I used