Batch Text to Aiff workflow using loop in AppleScript

Hi All,

Firstly, what a cool site! I’m very new to AppleScript and in fact programming full stop. I am working on a very simple application outputs all text files in a given project into a specific sub-directory of the project, however, it’s not working properly. I’m getting an end of file error (error -39) and can’t work out why.

In theory (well, tested throughout by outputting the vars in dialogs too) the script

  1. takes the filenames of the txt files that are passed into it,
  2. strips the extension then
  3. builds the links to the _audio directory & filename to output the file later
  4. gets the contents of the text file into a var
  5. records them into the specified output directory as speech

My projects are audio tutorials that are always in the same root folder (…/Documents/My LearnThruSong Revision Projects/(Project Name)/(Track Name).Each project has a specific set of sub directories - ‘_audio’ and ‘_text_to_convert’.

The process in Automator

Choose finder items … (locked to tyoe text)
pass those files into applescript then run the following applescript:

on run {input, parameters}
	set fileChoice to input
	set i to 1
	repeat with thisFile in fileChoice
		set thisTxtFilePath to thisFile as string
		set AppleScript's text item delimiters to "/"
		set txtFileName to last text item of thisTxtFilePath --as string 
		set projectDirectory to text items 1 thru -3 of thisTxtFilePath --as string
		set audioPath to projectDirectory & "_audio" 
		set AppleScript's text item delimiters to "."
		set stripTxtNameExtension to first text item of txtFileName --as string
		set AppleScript's text item delimiters to "/"
		set audioFileName to stripTxtNameExtension & ".aiff" --as string
		set AppleScript's text item delimiters to "/"
		set outPut_Aif to audioPath & audioFileName
		set OutList to text items 1 thru -1 of outPut_Aif
		set Finaloutput to OutList as string
		display dialog Finaloutput
		set AppleScript's text item delimiters to {""}
		open for access thisTxtFilePath
		set fileContents to (read thisTxtFilePath)
		close access thisTxtFilePath
		say fileContents using Alex saving to file Finaloutput
		set i to i + 1
	end repeat
end run

Any help would be greatly appreciated!!!



Model: MacPro 8x2.8GHz
AppleScript: 2.1.2 (Editor - v2.3)
Browser: Mozilla/5.0 (000000000; 00000 000 00 0 0000; 00000000) DDDDDDDDDDDDDD DDDDDDDDDDDDD
Operating System: Mac OS X (10.6)