Detecting between audio and video when opening Quicktime file

I’d like to adjust the size of the Quicktime window and trigger some other events, depending on whether it’s a video file or an audio file that’s just opened. Does anybody know how to detect if the file is audio only or audio/video, and how to set up Applescript to do the check when a file opens (as opposed to only checking when the app launches?

I’m using Quicktime v. 7.6.6, if that makes a difference. The file types are likely to be almost anything that QT supports.

Thanks.

Model: G5
AppleScript: 2.0.1
Browser: Safari 5.0 (533.16)
Operating System: Mac OS X (10.5)

You have to look a the dictionary. You’ll see that a document contains tracks. And the tracks have many properties, one of them being type. So you can look at the type and see if it is of type “vide” (eg. video). It’s all there in the dictionary so you need to learn to use it.

set containsVideo to false
tell application "QuickTime Player 7"
	tell document 1
		set theTracks to tracks
		repeat with aTrack in theTracks
			if type of aTrack is "vide" then
				set containsVideo to true
				exit repeat
			end if
		end repeat
	end tell
end tell
return containsVideo

Thanks for this, Hank. I could see it in the dictionary, but couldn’t make anything that worked. Your approach is what makes it useful. Elegant, even.

Having said that, your approach seems to work in some cases, but not in others. For example running it against one video produced this event log:

tell application “QuickTime Player”
get every track of document 2
{track 1 of document “Community Forest Video.m4v”, track 2 of document “Community Forest Video.m4v”}
get type of track 1 of document “Community Forest Video.m4v”
“soun”
get type of track 2 of document “Community Forest Video.m4v”
“vide”
end tell

and the result, as expected, is True.

However, running it against another video produced this event log:

tell application “QuickTime Player”
get every track of document 1
{track 1 of document “rango_963_320x128.mpg”}
get type of track 1 of document “rango_963_320x128.mpg”
“MPEG”
end tell

and the result, unexpectedly for me, at least, was False, which upon reflection maybe is because the result wasn’t ‘vide’ but ‘MPEG’.

I thought they both should have been True as they’re both videos, as the app’s dictionary seems to suggest. As you can see by the file names, however, they’re different kinds of video.

In your script, I tried changing ‘type’ to ‘kind’ and ‘Video’ as that seems to be an alternate in the dictionary, but the result was the same.

I’m not sure what the perfect solution is then. Maybe video depth?

repeat with aTrack in theTracks
			try
				if video depth of aTrack is greater than 0 then
					set containsVideo to true
					exit repeat
				end if
			end try
		end repeat

Or maybe you can do something with “data rate”. I guess you’ll just have to muck something together to try to catch every case.

Hi,
video files contain at least one track whose dimensions are not {0.0, 0.0}


set theFile to (choose file) as text
set isVideo to false
tell application "QuickTime Player"
	open theFile
	set dim to dimensions of tracks of document 1
end tell
repeat with d in dim
	if contents of d is not {0.0, 0.0} then
		set isVideo to true
		exit repeat
	end if
end repeat

I haven’t looked into it thoroughly, but I’d imagine their ‘natural dimensions’ are never {0, 0} either.


set theFile to (choose file)
tell application "QuickTime Player"
	set theDoc to (open theFile)
	set isVideo to (theDoc's natural dimensions is not {0, 0})
end tell

Those last three approaches all work well for my purposes! Thanks so much for taking the time to do that, and for teaching me more about how to handle Applescript!

Cheers!