Convert 1 File Selecting Applescript to handle multiple files?

I have the following script which processes one audio file, I’m hoping to convert it to do the exact same process for however many files I select.

Does anyone know how to do this?

property type_list : {"AIFC", "AIFF", "MPG3", "MooV", "NeXT", "Sd2f", "WAVE"}

property extension_list : {"aif", "aiff", "mp3", "m4a", "sdII", "mov", "au", "wav"}

on run
	try
		set myFile to choose file with prompt "Please Pick a File" of type type_list default location (path to desktop) without invisibles and multiple selections allowed
		processFile(myFile)
	on error errText number errNum
		if (errNum is equal to -128) then
		end if
	end try
end run

on loadFiles(this_file)
	repeat with one_item in this_file
		my processFile(one_item)
	end repeat
end loadFiles

on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
			processFile(this_item)
		end if
	end repeat
end open

on processFile(this_file)
	with timeout of 600 seconds
		tell application "Soundtrack Pro"
			activate
			open this_file
		end tell
		
		process()
		try
			tell application "Soundtrack Pro"
				tell front audio file document
					save
					close saving no
				end tell
			end tell
		on error errMsg number errNum
			display dialog errMsg & "/" & errNum buttons {"OK"} default button 1
			return "error"
		end try
	end timeout
end processFile

on process()
	with timeout of 600 seconds
		try
			tell application "Soundtrack Pro"
				activate
				
				tell front audio file document
					set theEntireDuration to the duration
					make new normalize action at after last action with properties {position:0.0, duration:theEntireDuration, enabled:true, channel:1, name:"NormalizeOperation", preset state:"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict>	<key>data</key>	<data>	AAAAAAAAAAAAAAACAAAAAEANWfkAAAABAAAAAA==	</data>	<key>manufacturer</key>	<integer>1952542846</integer>	<key>name</key>	<string>Untitled</string>	<key>subtype</key>	<integer>1987013664</integer>	<key>type</key>	<integer>1635085688</integer>	<key>version</key>	<integer>0</integer></dict></plist>", normalization level:-1.0}
				end tell
			end tell
		on error errMsg number errNum
			display dialog errMsg & "/" & errNum buttons {"OK"} default button 1
			return "error"
		end try
	end timeout
end process


on process_folder(this_folder)
	set these_items to list folder this_folder without invisibles
	repeat with i from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item i of these_items))
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
			processFile(this_item)
		end if
	end repeat
end process_folder

Is this saved as an application? Have you tried dropping multiple files on it?

I believe your script is getting confused at the prompt “without invisibles and multiple selections allowed”

Change it to this instead:

set myFile to choose file with prompt "Please Pick a File" of type type_list default location (path to desktop) with multiple selections allowed without invisibles

Hmm, good eye Torajima, although it still only processes one file.

Thanks Jacques, I’ll give that a try. I’m sure you can tell I’m a n00b with applescript, and haven’t found any documentation for learning the language yet. I’m good with actionscript although :slight_smile: