Quicktime scripting question, works, but some questions

The script opens a folder and processes only audio files (wav’s, aif’s, or mp3’s), then opens each in QT and gets their duration in minutes and seconds. The questions that I have are in the comments, which start with “***”. Any help would be appreciated. I’m using Tiger 10.4.4 and the latest version of QT.


property extension_list : {"AIFF", "MPG3", "WAVE"}
tell application "Finder"
	activate
	set name_text to ""
	set mycount to 1
	set this_folder to choose folder with prompt "Choose a folder to list:"
	set the folder_items to (every item of this_folder)
	-- set the folder_path to this_folder as string
	repeat with i from 1 to the count of the folder_items
		set this_item to (item i of the folder_items)
		try
			if (the file type of this_item is in the extension_list) then
-- ******** I have to open an alias. If I open the actual reference, it opens in the default application for that file instead of Quicktime - why?
				set this_one to this_item as alias
				tell application "QuickTime Player"
					open this_one
					set the time_scale to the time scale of movie 1
					set the movie_duration to the duration of movie 1
-- ******* this calculation has to happen all in one step. If I try and break it down into multiple steps, it breaks the script:
					set the movie_length to ((((movie_duration / time_scale) div 60) * 10 div 10) as string) & ":" & (((((movie_duration / time_scale / 60) - ((movie_duration / time_scale) div 60)) * 60) * 10 div 10) as string)
					close movie 1
				end tell
				set name_text to name_text & mycount & "   " & the name of this_item & "     " & movie_length & (ASCII character 13)
				set mycount to mycount + 1
			end if
		on error error_message number error_number
		end try
	end repeat
	display dialog name_text
end tell

Hi,

I’m still using Jaguar, but think most of this applies to both OSs.

The alias file is different from an AppleScript alias reference. Furthermore, an alias reference has a different form than a Finder reference. A Finder reference might look like this:

alias file “test.txt” of folder “Desktop” of folder “kel” of folder “Users” of startup disk of application “Finder”

After you coerce this to an AppleScript alias reference with ‘as alias’ it looks like this:

alias “Macintosh HD:Users:kel:Desktop:test.txt alias”

Your files were probably opening in the default application because you were using a Finder reference. In other words, the Finder was opening the files. It didn’t matter if the files were files or alias files.

About the calculation. It’s hard to know what was wrong without seeing your original broken down calculation.

Editted: BTW, you should take the QT Player tell block out of the Finder tell block. Close up the Finder tell block because it is not needed after you get the references. Nested tell blocks often cause trouble.

gl,

Thanks!