Add and Add Scaled "SMIL Sequence Wizard" adjustements

Dear scripters,

Thank jou for youre time, this is my question:

There is a script called SMIL Sequence Wizard it combines audio files with images (images in pre adjusted time) and also gives the inserted items URL’s. This is mostly what i need but not in the right way as it is done know. SMIL Sequence Wizard now put everyting in order of asked behind each other. What i really need is to choose an audio file intergrade it into the new made movie and after that choosse a picture and make it as long as the first selected audio file starting also at the same point as this audio file (in quicktime pro this is done with “Add and Add Scaled”) after that the picture should be provided by the right URL and then the new audio file should be selected wile the whole thing runs again so picture add and add scaled to the second audio file, URL etc.

i hope this is clear here is my adjusted SMIL Sequence Wizard it now accepts all audio and picture files (the real one doesn’t),



tell application "QuickTime Player"
	activate
	stop every document
	
	-- prompt for a name and location of the SMIL file
	set SMILfile_name to "smil.mov"
	repeat
		set the SMIL_file to (choose file name with prompt "Enter a name and location for the created SMIl file:" default name SMILfile_name) as text
		set AppleScript's text item delimiters to ":"
		set the SMILfile_name to last item of (text items of the SMIL_file)
		set the parent_folder to ¬
			((the reverse of the rest of the reverse of (the text items of the SMIL_file)) as string) & ":"
		set AppleScript's text item delimiters to ""
		if the SMILfile_name ends with ".mov" then
			exit repeat
		else
			display dialog "The file name must end with ".mov""
		end if
	end repeat
	
	if (exists document 1) then
		set the button_list to {"Cancel", "Use Front Movie", "OK"}
	else
		set the button_list to {"Cancel", "OK"}
	end if
	
	-- prompt for the width of the SMIL presentation area
	set the low_number to 72
	set the high_number to 2000
	repeat
		display dialog "Enter a presentation window WIDTH in pixels:" default answer "" buttons button_list default button (last item of the button_list)
		copy the result as list to {window_width, button_pressed}
		try
			if the button_pressed is "OK" then
				if the window_width is not "" then
					set the window_width to the window_width as integer
					if the window_width is greater than or equal to the low_number and ¬
						the window_width is less than or equal to the high_number and ¬
						the window_width mod 1 is equal to 0 then exit repeat
				end if
			else -- use the width of the front movie
				copy the natural dimensions of document 1 to {movie_width, movie_height}
				set the window_width to the movie_width
				if the window_width is greater than or equal to the low_number and ¬
					the window_width is less than or equal to the high_number and ¬
					the window_width mod 1 is equal to 0 then exit repeat
			end if
		end try
	end repeat
	
	set the default_height to (((window_width * 3) / 4) div 1) as text
	
	-- prompt for the height of the SMIL presentation area
	set the low_number to 72
	set the high_number to 2000
	repeat
		display dialog "Enter a presentation window HEIGHT in pixels:" default answer default_height buttons button_list default button (last item of the button_list)
		copy the result as list to {window_height, button_pressed}
		try
			if the button_pressed is "OK" then
				if the window_height is not "" then
					set the window_height to the window_height as integer
					if the window_height is greater than or equal to the low_number and ¬
						the window_height is less than or equal to the high_number and ¬
						the window_height mod 1 is equal to 0 then exit repeat
				end if
			else -- use the height of the front movie
				copy the natural dimensions of document 1 to {movie_width, movie_height}
				set the window_height to the movie_height
				if the window_height is greater than or equal to the low_number and ¬
					the window_height is less than or equal to the high_number and ¬
					the window_height mod 1 is equal to 0 then exit repeat
			end if
		end try
	end repeat
	
	display dialog "Choose a default background color:" buttons {"Cancel", "White", "Black"}
	if the button returned of the result is "White" then
		set the background_color to "background-color=\"white\" "
	else if the button returned of the result is "Black" then
		set the background_color to "background-color=\"black\" "
	end if
	
	display dialog "Should the SMIL movie automatically play when it is loaded?" buttons {"Cancel", "Yes", "No"}
	if the button returned of the result is "Yes" then
		set autoplay_value to "true"
	else
		set autoplay_value to "false"
	end if
	
	display dialog "Should the time slider button be displayed on the controller?" buttons {"Cancel", "Yes", "No"}
	if the button returned of the result is "Yes" then
		set slider_value to "true"
	else
		set slider_value to "false"
	end if
	
	-- generate the opeining SMIL text
	set the SMIL_text to ""
	set the SMIL_text to the SMIL_text & "<smil xmlns:qt=\"http://www.apple.com/quicktime/resources/smilextensions\" qt:autoplay=\"" & autoplay_value & "\" qt:time-slider=\"" & slider_value & "\">" & return
	set the SMIL_text to the SMIL_text & tab & "<head>" & return
	set the SMIL_text to the SMIL_text & tab & tab & "<layout>" & return
	set the SMIL_text to the SMIL_text & tab & tab & tab & "<root-layout width=\"" & window_width & "\" height=\"" & window_height & "\" " & background_color & "/>" & return
	set the SMIL_text to the SMIL_text & tab & tab & tab & "<region id=\"region_1\" left=\"0\" top=\"0\" width=\"" & ¬
		window_width & "\"" & " height=\"" & window_height & "\" fit=\"fill\" />" & return
	set the SMIL_text to the SMIL_text & tab & tab & "</layout>" & return
	set the SMIL_text to the SMIL_text & tab & "</head>" & return
	set the SMIL_text to the SMIL_text & tab & "<body>" & return
	set the SMIL_text to the SMIL_text & tab & tab & "<seq>" & return
	
	
	-- add the items
	set the loop_counter to 1
	repeat
		if the loop_counter is 1 then
			set the button_pressed to "Add Item"
		else -- don't show this dialog the first time through the repeat loop
			display dialog "Add another item to the SMIL sequence?" buttons {"Cancel", "Add Item", "Done"}
			set the button_pressed to the button returned of the result
		end if
		if the button_pressed is "Done" then
			exit repeat
		else
			set the duration_text to ""
			display dialog "Add a movie or an image?" buttons {"Cancel", "Movie", "Image"}
			set the item_type to the button returned of the result
			if the item_type is "Image" then
				set the src_type to "img"
				set the type_list to {"MPG3", "MIDI", "AIFF", "MooV", "MPG", "PLAY"}
				set the display_type to "JPEG image"
			else
				set the src_type to "audio"
				set the type_list to {"MPG3", "MIDI", "AIFF", "MooV", "MPG", "PLAY"}
				set the display_type to "movie"
			end if
			set the movie_counter to my add_numeric_suffix(loop_counter)
			display dialog "Choose the source of the " & movie_counter & " item to add to the SMIL sequence:" buttons {"Cancel", "File", "URL"}
			if the button returned of the result is "URL" then
				display dialog "Will the added item be located in the same folder as the generated SMIL file?" buttons {"Cancel", "Yes", "No"}
				if the button returned of the result is "Yes" then
					display dialog "Enter the name of the " & movie_counter & " item to add:" default answer ""
					set the item_URL to the text returned of the result
				else
					display dialog "Please enter the URL of the " & movie_counter & " item to add:" & return & return & ¬
						"either relative to the SMIL file location:" & return & space & space & "/media/this_item.mov" & return & return & ¬
						"or as a complete URL:" & return & space & space & "http://www.mysite.com/media/this_item.mov" default answer ""
					set the item_URL to the text returned of the result
				end if
			else -- choose a file
				if the item_type is "Image" then
					set this_movie to ""
				else
					try
						set this_movie to the original file of document 1
						if this_movie is "" then error
					on error
						set this_movie to ""
					end try
				end if
				if this_movie is not "" then
					display dialog "Add the front movie?" buttons {"Cancel", "Yes", "Choose Other"}
					if the button returned of the result is "Yes" then
						set the item_path to this_movie
					else
						set the item_path to choose file of type type_list with prompt "Choose the " & movie_counter & " item (" & display_type & ") to add:"
					end if
				else
					set the item_path to choose file of type type_list with prompt "Choose the " & movie_counter & " item (" & display_type & ") to add:"
				end if
				set the item_URL to my GenerateTheLink(parent_folder, item_path)
				set the item_URL to my encode_text(item_URL, false, false)
			end if
		end if
		
		if the item_type is "Image" then
			repeat
				try
					display dialog "Enter the number of seconds the image should be displayed:" default answer "1"
					set the num_seconds to (the text returned of the result) as integer
					if the num_seconds is not 0 then
						set the num_seconds to the num_seconds as string
						set the duration_text to "dur=\"" & num_seconds & "s\" "
						exit repeat
					end if
				on error number error_number
					if the error_number is -128 then return "user cancelled"
				end try
			end repeat
		end if
		
		display dialog "Should this item be fully loaded before the SMIL movie plays?" & ¬
			return & return & "NOTE: preloading items will increase the time before playback." buttons {"Cancel", "Yes", "No"}
		if the button returned of the result is "Yes" then
			set the preload_text to "qt:immediate-instantiation=\"true\" "
		else
			set the preload_text to ""
		end if
		
		display dialog "Should clicking on this item open a link to a specific webpage?" buttons {"Cancel", "Yes", "No"}
		if the button returned of the result is "Yes" then
			-- prompt for the target link URL
			repeat
				display dialog "Enter the target URL link:" default answer "http://"
				set the target_URL to the text returned of the result
				if the target_URL is not "" then exit repeat
			end repeat
			-- prompt whether to open in same page or new page
			display dialog "Open the target URL in the same page as this item or in a new page?" buttons {"Cancel", "Same", "New"}
			set the destination_page to the button returned of the result
			if the destination_page is "Same" then
				set the display_method to "pause"
			else
				set the display_method to "new"
			end if
			set this_movie to "movie"
			if the loop_counter is 1 then
				set the pause_length to 0
			else
				set the low_number to 0
				set the high_number to 10000
				repeat
					display dialog "Enter the length of the pause (in seconds) between this item and the previous item: " default answer "0"
					try
						if the text returned of the result is not "" then ¬
							set the pause_length to the text returned of the result as number
						if the pause_length is greater than or equal to the low_number and ¬
							the pause_length is less than or equal to the high_number and ¬
							the pause_length mod 1 is equal to 0 then exit repeat
					end try
				end repeat
			end if
			set the SMIL_text to the SMIL_text & tab & tab & tab & "<a href=\"" & target_URL & "\" show=\"" & display_method & "\">" & return
			set the SMIL_text to the SMIL_text & tab & tab & tab & tab & "<" & src_type & " src=\"" & item_URL & "\" alt=\"" & ¬
				display_type & "\" region=\"region_1\" begin=\"" & (pause_length as text) & "s\" " & duration_text & preload_text & "/>" & return
			set the SMIL_text to the SMIL_text & tab & tab & tab & "</a>" & return
		else
			set this_movie to "movie"
			if the loop_counter is 1 then
				set the pause_length to 0
			else
				set the low_number to 0
				set the high_number to 10000
				repeat
					display dialog "Enter the length of the pause (in seconds) between this item and the previous item: " default answer "0"
					try
						if the text returned of the result is not "" then ¬
							set the pause_length to the text returned of the result as number
						if the pause_length is greater than or equal to the low_number and ¬
							the pause_length is less than or equal to the high_number and ¬
							the pause_length mod 1 is equal to 0 then exit repeat
					end try
				end repeat
			end if
			set the SMIL_text to the SMIL_text & tab & tab & tab & "<" & src_type & " src=\"" & item_URL & "\" alt=\"" & display_type & "\" region=\"region_1\" begin=\"" & ¬
				(pause_length as text) & "s\" " & duration_text & preload_text & "/>" & return
		end if
		set the loop_counter to the loop_counter + 1
	end repeat
	
	set the SMIL_text to the SMIL_text & tab & tab & "</seq>" & return
	set the SMIL_text to the SMIL_text & tab & "</body>" & return
	set the SMIL_text to the SMIL_text & "</smil>"
	
	set the temp_file to ((parent_folder as text) & ("temp" & (random number from 1000000 to 9999999) as text) & ".smi")
	if my write_to_file(SMIL_text, temp_file, false) is false then
		beep
		-- if the sub-routine returns a false value then display this error dialog
		display dialog "There was a problem writing to the temp file. " & ¬
			"Is this file open? If so, close the file and try again." buttons {"Cancel"} default button 1
	end if
	
	try
		display dialog "Opening temp file." buttons {"¢"} giving up after 2
		set current_status to open movie in new player
		set open movie in new player to true
		open file temp_file
		set open movie in new player to current_status
		
		if autoplay_value is "true" then
			stop every document
			rewind document 1
		end if
		
		display dialog "Enter a title for the movie:" default answer SMILfile_name
		set the full text of annotation "Full Name" of the front document to the text returned of the result
		
		display dialog "Saving temp file as SMIL movie." buttons {"¢"} giving up after 2
		save document 1 given «class dfil»:file SMIL_file, «class savk»:self contained
		
		tell application "Finder"
			delete file temp_file
			empty trash
		end tell
		
		display dialog "Do you want to save a copy of the SMIL code in a text file?" buttons {"Yes", "No"}
		if the button returned of the result is "Yes" then
			set the target_file to choose file name with prompt "Choose a name and location for the SMIL text file:" default name "SMIL.txt"
			my write_to_file(SMIL_text, target_file, false)
		end if
		
		display dialog "Process completed." buttons {"¢"} giving up after 2
	on error error_message number error_number
		if the error_number is not -128 then
			display dialog error_message buttons {"Cancel"} default button 1
		end if
	end try
end tell



on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as text
		set the open_target_file to ¬
			open for access file target_file with write permission
		if append_data is false then ¬
			set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

on GenerateTheLink(theBaseFolder, theTargetFile)
	try
		--set theBaseFolder to choose folder with prompt "Pick the folder that contains or will contain this HTML file:"
		set theAList to ConvertPathToList(theBaseFolder)
		--set theTargetFile to choose file with prompt "Pick the file to link to:"
		set theBList to ConvertPathToList(theTargetFile)
		
		if item 1 of theAList ≠ item 1 of theBList then
			beep
			display dialog "The parent folder and the target file must be on the same disk." buttons {"Cancel"} default button 1
		end if
	on error
		return 0
	end try
	
	repeat
		try
			set theAItem to item 1 of theAList -- if the target file is in the parent folder this will eventually fail
			set theBItem to item 1 of theBList
		on error
			set theLink to my DelineateWithSlashes(theBList)
			return theLink
			--return "\"" & theLink & "\""
		end try
		if theAItem ≠ theBItem then --the file is outside the folder
			set theLink to (my DelineateWithSlashes(theBList))
			--add ../ before the result for each item of theAList
			repeat (the number of items of theAList) times
				set theLink to ("../" & theLink) as string
			end repeat
			return theLink
			--return "\"" & theLink & "\""
		end if
		set theAList to the rest of theAList
		set theBList to the rest of theBList
	end repeat
end GenerateTheLink

on DelineateWithSlashes(thisList)
	set theLink to ""
	repeat with thisItem in thisList
		set theLink to (theLink & "/" & thisItem) as string
		--remove the first "/"
		if character 1 of theLink is "/" then ¬
			set theLink to (characters 2 thru -1 of theLink) as string
	end repeat
	return theLink
end DelineateWithSlashes

on ConvertPathToList(thisPath)
	set thisPath to thisPath as text
	set thePathList to {}
	try
		repeat
			set x to offset of ":" in thisPath
			set theItem to (characters 1 thru (x - 1) of thisPath) as string
			set thePathList to thePathList & theItem
			if x is 0 then exit repeat
			set thisPath to (characters (x + 1) thru -1 of thisPath) as string
		end repeat
	end try
	return thePathList
end ConvertPathToList


-- this sub-routine converts a filepath to an encoded URL
-- My Disk:My Folder:My File
-- My%20Disk/My%20Folder/My%20File
on filepath_to_URL(this_file, encode_URL_A, encode_URL_B)
	set this_file to this_file as text
	set AppleScript's text item delimiters to ":"
	set the path_segments to every text item of this_file
	repeat with i from 1 to the count of the path_segments
		set this_segment to item i of the path_segments
		set item i of the path_segments to my encode_text(this_segment, encode_URL_A, encode_URL_B)
	end repeat
	set AppleScript's text item delimiters to "/"
	set this_file to the path_segments as string
	set AppleScript's text item delimiters to ""
	return this_file
end filepath_to_URL

-- this sub-routine is used to encode text
on encode_text(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to ¬
		"abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to ¬
				(the encoded_text & this_char)
		else
			set the encoded_text to ¬
				(the encoded_text & encode_char(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encode_text

-- this sub-routine is used to encode a character
on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to ¬
		{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
			"9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char

on add_numeric_suffix(this_num)
	set the list_index to (this_num mod 10) + 1
	set the num_suffix to item list_index of ¬
		{"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}
	return ((this_num as text) & the num_suffix)
end add_numeric_suffix


Model: Mac Mini Intel
AppleScript: new
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)