getting document name from open quicktime movie

I have an applescript that gets the time scale from a movie opened in Quicktime Player. It works if the movie’s name (document name) is the same as its file name.

The following opens a file ‘Introduction.mov’ that has a name annotation of ‘Introduction.mov’

tell application "QuickTime Player"
	set sound_movie to "Macintosh HD:Users:instructor:Movies:Introduction.mov"
	set SoundMov to open sound_movie as alias

        --the lines below gets the document name from the file name
        set AppleScript's text item delimiters to ":"
	set sourcemoviename to the last text item of (the sound_movie as string)

	set time_scale to the time scale of document sourcemoviename
	
	display dialog "the time scale is: " & time_scale
end tell

Sometimes the document name of a movie is different than the file name. For some reason that was the case with an .mp4 version of the above movie file ‘Introduction.mp4’ that has a name annotation ‘Introduction 01’. In that case the script above fails. I have tried to get the name of the document once it is opened to ensure the script does not fail but I can’t figure out how to do it.

The following opens a file Introduction.mp4 that has a name annotation ‘Introduction 01’

tell application "QuickTime Player"
	set sound_movie to "Macintosh Leopard:Users:instructor1:Movies:Introduction.mp4"
	set SoundMov to open sound_movie as alias

	-- the line below is intended to get the name of the opened document 'Introduction 01'but will generate and error
	set sourcemoviename to the name of document SoundMov

	set time_scale to the time scale of document sourcemoviename
	
	display dialog "the time scale is: " & time_scale
end tell

how do I retrieve the properties of an open quicktime movie in Quicktime Player.

BTW this is using Quicktime 7.5.5, Mac OS X 10.5.5 and applescript 2.0.1

mkoob

Hi,

try this

tell application "QuickTime Player"
	set sound_movie to "Macintosh HD:Users:instructor:Movies:Introduction.mov"
	open sound_movie as alias
	tell document 1
		set sourcemoviename to name
		set time_scale to the time scale
	end tell
end tell
display dialog "the time scale of file " & sourcemoviename & " is: " & time_scale

Thanks that worked!

I was wondering though, could it be the case that another movie could be opened by another script or brought forward by an errant mouse click in between the two commands and end up to be document 1? Is there a way to access movie properties using the SoundMov variable created with the result of the open command? This would ensure I was working with the correct movie.

Thanks

mkoob

yes, this is also possible


tell application "QuickTime Player"
	set sound_movie to "Macintosh HD:Users:instructor:Movies:Introduction.mov"
	set SoundMov to open sound_movie as alias
	if class of SoundMov is list then set SoundMov to item 1 of SoundMov -- under some circumstances the open command returns a list
	tell SoundMov
		set sourcemoviename to name
		set time_scale to the time scale
	end tell
end tell
display dialog "the time scale of file " & sourcemoviename & " is: " & time_scale

thanks Stefan

that worked perfectly

Martin