Catalina killed my QuickTime Player script

Hello all,

I had a couple of scripts running, ever since macOS Yosimite I think, that now seem to fail after migrating to Catalina.

Here is what happens:
I have a TV-recording-file of about 2 hour long that contains Flower Power clips.
I have defined start- and stop-positions of each clip and have an applescript that takes care of the trimming.
As I said, the script has been running fine for years, but now I cannot get it to work any longer.

The script:
set savePath to (the path to the desktop folder as text) & “__716.m4v”

set unixFile to “/Volumes/4TP1/BackUp/Top40/1111-11-11.m4v”
set macFile to POSIX file unixFile

tell application “QuickTime Player”
activate
try
stop the front document
close saving no
close the front document
end try

open macFile

set theDuration to the duration of the front document

delay 4

set tDoc to open file macFile
tell tDoc
set current time to theDuration
delay 4
– position at the title, just for a nice preview
set current time to 731
delay 4
do shell script "echo " & “‘==== theDuration = " & theDuration & " ====’ > /tmp/debug_out”
do shell script "echo " & “‘trim from 716 to 1082’ >> /tmp/debug_out”
trim from 716 to 1082
end tell

delay 4

export the front document in file savePath using settings preset “1080p”

delay 4

try
stop the front document
close the front document without saving
end try
end tell

The delays and shell-script lines are there just for myself, just to be able to find out what is going on.
The lines:
set current time to theDuration and
set current time to 731
are there, just to make sure the start- and endpositions are OK, and they are! QuickTime Player flawlessly positions on both frames.

When running the script however I get:
% osascript < _Applescript_8134_trim
767:788: execution error: QuickTime Player got an error: End time must be less than or equal to duration (6)

/tmp/debug_out contains:
==== theDuration = 7187.04 ====
trim from 716 to 1082

I have tried integer as well as float representations of the start- and stop-numbers but nothing seems to work anymore.

Anybody any clues on to how to get it going again? Thanks!

Model: MacBook Pro (late 2013), macOS 10.15.4
Browser: Safari 605.1.15
Operating System: macOS 10.14

I don’t know. On Mojave the following script works fine:


set savePath to (path to the desktop folder as text) & "__716.m4v"
set macFile to choose file of type "m4v"

tell application "QuickTime Player"
	activate
	close documents saving no
	close windows
	
	tell (open macFile)
		set theDuration to duration -- set TO time
		set current time to theDuration / 2 -- set FROM time
		trim from (current time) to theDuration
	end tell
	
	export front document in file savePath using settings preset "1080p"
	close documents saving no
	close windows
	quit
end tell

I know… Mine worked fine under Mojave too…

Still, no luck under Catalina.

MacAdam,

I didn’t tell you: most likely it’s not bug of Catalina. I ran your script on Mojave and got the same error as you. Then I ran my script, and the clip was safely saved to the desktop.

I think the whole point is that you open the same clip twice, and the second time you open the clip incorrectly. The fact is that the reference you specified at the beginning:


set macFile to POSIX file unixFile

is already a file reference, not a Posix path. Therefore, coercion file MacFile should not be performed.

So, you definitely ran my script as is? Changing nothing in it? I use alias (instead of file reference), with which QuickTime Player works fine.

Well, I agree that I should not have opened the macfile twice but removing the ‘open macFile’-line did not produce different results.

What DID make things going was, instead of just ‘trim from 716 to 1082’:

try
trim from 716 to 1082
end try

heaven knows why, but my script again started to do what it has been doing for years!

Well, you just hid the error, not corrected it. In addition, you do not understand. I already told you that you need to remove the second opening of the file, which is incorrect. And you removed the correct opening of the file - the first. If you really do not want to just run someone else’s script… it is really difficult to learn something.

I have modified my script so that it looks exactly like yours…
It works well, but it DOES need the try/end try around the trim, otherwise it keeps complaining about the end time (End time must be less than or equal to duration (6)).

set savePath to (the path to the desktop folder as text) & “__716.m4v”

set unixFile to “/Volumes/4TP1/BackUp/Top40/1111-11-11.m4v”
set macFile to POSIX file unixFile

tell application “QuickTime Player”
activate
close documents saving no
close windows

tell (open macFile)
set theDuration to duration
– position at the title, just for a nice preview
set current time to 731
delay 4
try
trim from 716 to 1082
end try
end tell
delay 4

export the front document in file savePath using settings preset “1080p”
delay 4

close documents without saving
close windows
end tell

Now guess what… This works too:

tell (open macFile)
set theDuration to duration
– position at the title, just for a nice preview
– set current time to 731
– delay 4
– try
trim from 716 to 1082
– end try
end tell

I wonder if the ‘set current time’ is the one that confuses QuickTime Player…???

Now I AM confused…

It runs in about 8 of 10 times, it complains about the end time on the other 2 occasions…

After changing the code to:

tell (open macFile)
set theDuration to duration
– position at the title, just for a nice preview
set current time to 731
delay 4
try
trim from 716 to 1082
end try
end tell

it runs just fine 10 out of 10 times…

Your settings 731, 716 and 1082 should not be longer than the total duration of your clip. The way you use try block, without catching the error, just hides this error, does not fix it.

Add at end of last script:

return theDuration

to see what is the duration of your clip

See my original posting…

/tmp/debug_out contains:
==== theDuration = 7187.04 ====
trim from 716 to 1082

The movie is about 2 hours long…

Dear KniazidisR,

Can you please indicate what version of Catalina you are running?
I run 10.15.4 (19E264b)

And starting today (mar 28) that is: macOS 10.15.4 (19E266)

Kind regards,
Adam

Hi, MacAdam.

I just switched to Catalina, and now I can answer your question definitely: the trim command of the QuickTime Player application has an insignificant but unpleasant bug: it cuts the movie correctly, but for some reason it gives an error message for the error that does not exist.

To get rid of this stupid message, you can:

  1. Put the trim command in a try block, as you did.
  2. Ask Apple to fix the stupid bug.
  3. Put the trim command in the ignoring application responses block to gag the QuickTime Player application:

set savePath to (path to the desktop folder as text) & "__716.m4v"
set macFile to choose file of type "m4v"

tell application "QuickTime Player"
	activate
	close documents saving no
	close windows
	
	tell (open macFile)
		set aDuration to get duration
		set curTime to aDuration / 2
		ignoring application responses
			trim from curTime to aDuration
		end ignoring
	end tell
	
	export front document in file savePath using settings preset "1080p"
	close documents saving no
	close windows
end tell