Photoshop CS5.1 script used to work OSX 10.5 but not 10.7.

I use this script to downsize images in Photoshop CS5.1. It worked like a charm until I tried to use it on lion. Anyone know how to fix it?

I get the error message “File Some Error Not Found”

Thanks

on compileAsOption(valStr)
	tell application "Adobe Photoshop CS5.1"
		run script "tell application \"Adobe Photoshop CS5.1\" to return {«class fltp»:" & valStr & "}"
	end tell
end compileAsOption

set inputFolder to choose folder with prompt "Pick your TOP level folder!"
--
tell application "Finder"
	set filesList to (files of entire contents of inputFolder)
end tell
--
repeat with aFile in filesList
	set fileIndex to 0
	tell application "Finder"
		set theFile to aFile as alias
		set theFileName to name of theFile
		set the subFolder to the container of theFile
	end tell
	--
	tell application "Adobe Photoshop CS5.1"
		activate
		set UserPrefs to properties of settings
		set ruler units of settings to pixel units
		--
		open theFile showing dialogs never
		set docRef to the current document
		tell docRef
			set docName to name of docRef
			set docBaseName to getBaseName(docName) of me
			--if (mode is not RGB) then
			--change mode to RGB
			--end if
			--if (bits per channel is sixteen) then
			--set bits per channel to eight
			--end if
			--set myOptions to {class:save for web export options, optimized size:true, quality:40, with profile:false} & my compileAsOption("JPEG") --I added a couple of additional options I use. Feel free to delete if you don't want them
			--set myExportOptions to {«class fltp»:JPEG, quality:40}
			--resizing images proportionaly and non proportionaly scaled
			
			convert to profile "sRGB IEC61966-2.1" intent absolute colorimetric with blackpoint compensation and dithering
			filter current layer using unsharp mask with options ¬
				{amount:130, radius:3, threshold:18}
			
			--
			resize image height 240 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & docBaseName & ".jpg"
			export docRef in file newFileName as save for web with options {class:save for web export options, web format:JPEG, with profile:true, quality:50, optimized size:true}
			--
			resize image height 120 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & "th_" & docBaseName & ".jpg"
			export docRef in file newFileName as save for web with options {class:save for web export options, web format:JPEG, with profile:true, quality:60, optimized size:true}
		end tell
		--
		close current document saving no
		--
		set ruler units of settings to ruler units of UserPrefs
		--
	end tell
end repeat
--
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

Ok I got it to work. Kind of…

The last thing is the filenames are messed up now. The original file name is appearing in the new image file name.

2573968_2.tif2573968_2.jpg should just be 2573968_2.jpg

Was working in CS3 fine. Any thoughts

Thanks in advance.

on compileAsOption(valStr)
	tell application "Adobe Photoshop CS5.1"
		run script "tell application \"Adobe Photoshop CS5.1\" to return {«class fltp»:" & valStr & "}"
	end tell
end compileAsOption

set inputFolder to choose folder with prompt "Pick your TOP level folder!"
--
tell application "Finder"
	set filesList to (files of entire contents of inputFolder)
end tell
--
repeat with aFile in filesList
	set fileIndex to 0
	tell application "Finder"
		set theFile to aFile as alias
		set theFileName to name of theFile
		set theFile to aFile as string
		set the subFolder to the contents of theFile
	end tell
	--
	tell application "Adobe Photoshop CS5.1"
		activate
		set UserPrefs to properties of settings
		set ruler units of settings to pixel units
		--
		open alias theFile showing dialogs never
		set docRef to the current document
		tell docRef
			set docName to name of docRef
			set docBaseName to getBaseName(docName) of me
			--if (mode is not RGB) then
			--change mode to RGB
			--end if
			--if (bits per channel is sixteen) then
			--set bits per channel to eight
			--end if
			--set myOptions to {class:save for web export options, optimized size:true, quality:40, with profile:false} & my compileAsOption("JPEG") --I added a couple of additional options I use. Feel free to delete if you don't want them
			--set myExportOptions to {«class fltp»:JPEG, quality:40}
			--resizing images proportionaly and non proportionaly scaled
			
			convert to profile "sRGB IEC61966-2.1" intent absolute colorimetric with blackpoint compensation and dithering
			filter current layer using unsharp mask with options ¬
				{amount:130, radius:3, threshold:18}
			
			--
			resize image height 240 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & docBaseName & ".jpg"
			export docRef in file newFileName as save for web with options {class:save for web export options, web format:JPEG, with profile:true, quality:50, optimized size:true}
			--
			resize image height 120 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & "th_" & docBaseName & ".jpg"
			export docRef in file newFileName as save for web with options {class:save for web export options, web format:JPEG, with profile:true, quality:60, optimized size:true}
		end tell
		--
		close current document saving no
		--
		set ruler units of settings to ruler units of UserPrefs
		--
	end tell
end repeat
--
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName