Photoshop CS Image processing script behaves oddly

Hello all,
I wrote this script for processing large groups of images from the finder using photoshop CS, and it works fine sometimes, but not others. The way it works is:
it gets a list of aliases from the finder, then opens them 1 by 1 in photoshop. It changes the image res to 170dpi. It checks if the image is grayscale, then changes it according to what the user said. Then it checks the image width, compares it to the user requested size, if its not big enough then it leaves it be, and writes the filename into a logfile for later checking. Finally it sharpens it and leaves it open.
Problem is, sometimes it will blow an image up bigger than it was, sometimes it won’t. Also, sometimes it will write the logfile and sometimes it won’t, even when there is info to be written.
As a side issue, when I port the script onto a machine running photoshop CS2, for some unknown reason, it subtracts the requested image size from the width, then resizes the image with the resulting figure.
I am at a loss. Please help. I have included the whole script. If you can fix it you are welcome to keep it and customise it to your needs as it is very handy…when it works.
Chuckles :smiley:

global ErrorLog
--if application "Finder" is frontmost then
set ColSizeList to {"1", "2", "3", "4", "5", "6", "7"}
set ImageSizeList to {"04", "08", "11", "15", "19", "23", "26"}
set FilesList to getFinderSelectionNow()
tell application "Adobe Photoshop CS2"
	activate
	set colourMode to display dialog "Colour or Mono?" buttons {"Cancel", "Mono", "Colour"} default button "Colour"
	if button returned of colourMode is "Cancel" then
		--do nothing
	else if button returned of colourMode is "Mono" then
		set MonoSizeList to choose from list ColSizeList with prompt "Choose a column size"
		set ErrorLog to return & "These images didn't make the requested size of " & MonoSizeList & " Columns." as text
		repeat with ColSize in MonoSizeList
			repeat with k from 1 to 7
				if item k of ColSizeList = contents of ColSize then
					set CMSize to item k of ImageSizeList
					my MonoModeResize(CMSize, FilesList)
					exit repeat
				end if
			end repeat
		end repeat
		
	else if button returned of colourMode is "Colour" then
		set ColourSizeList to choose from list ColSizeList with prompt "Choose a column size"
		set ErrorLog to return & "These images didn't make the requested size of " & ColourSizeList & " Columns." as text
		repeat with ColSize in ColourSizeList
			repeat with k from 1 to 7
				if item k of ColSizeList = contents of ColSize then
					set CMSize to item k of ImageSizeList
					my CMYKModeResize(CMSize, FilesList)
					exit repeat
				end if
			end repeat
		end repeat
	end if
end tell
--end if



on MonoModeResize(TheSize, FilesList)
	tell application "Adobe Photoshop CS2"
		activate
		repeat with i from 1 to number of items in FilesList
			set tempfile to item i of FilesList as alias
			tell application "Finder"
				set fileName to displayed name of tempfile
			end tell
			open tempfile
			tell document fileName
				set madeSize to true
				resize image resolution 170 resample method none
				set theWidth to (width as integer)
				set theMode to (mode as string)
				if theMode ≠ "grayscale" then
					change mode to grayscale
				end if
				if TheSize ≤ theWidth then
					resize image width TheSize
				else
					set madeSize to false
				end if
				filter layer 1 using unsharp mask with options {amount:110, radius:1.5, threshold:5}
			end tell
			if madeSize = false then
				set ErrorLog to ErrorLog & return & fileName
			end if
		end repeat
		if madeSize = false then
			my write_to_file(ErrorLog, true)
		end if
	end tell
end MonoModeResize


on CMYKModeResize(TheSize, FilesList)
	tell application "Adobe Photoshop CS2"
		activate
		repeat with i from 1 to number of items in FilesList
			set tempfile to item i of FilesList as alias
			tell application "Finder"
				set fileName to name of tempfile
			end tell
			open tempfile
			tell document fileName
				set madeSize to true
				resize image resolution 170 resample method none
				set theWidth to (width as integer)
				set theMode to (mode as string)
				if theMode ≠ "grayscale" then
					change mode to CMYK
				end if
				if TheSize ≤ theWidth then
					resize image width TheSize
				else
					set madeSize to false
				end if
				filter layer 1 using unsharp mask with options {amount:110, radius:1.5, threshold:5}
			end tell
			if madeSize = false then
				set ErrorLog to ErrorLog & return & fileName
			end if
		end repeat
		if madeSize = false then
			my write_to_file(ErrorLog, true)
		end if
	end tell
end CMYKModeResize


on getFinderSelectionNow()
	finderSelectionToAliasList()
end getFinderSelectionNow
on finderSelection()
	tell application "Finder" to get selection
end finderSelection
on finderSelectionToAliasList()
	finderDocListToAliasList(finderSelection())
end finderSelectionToAliasList

on finderDocListToAliasList(finderDocList)
	set aliasList to {}
	repeat with i in finderDocList
		set end of aliasList to finderDocToAlias(i)
	end repeat
	aliasList
end finderDocListToAliasList

on finderDocToAlias(finderDoc)
	tell application "Finder" to get finderDoc as alias
end finderDocToAlias


on write_to_file(this_data, append_data)
	try
		set the log_file to (path to desktop as text) & "Process Images Log" as text
		set the open_target_file to open for access file log_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 log_file
		end try
		return false
	end try
end write_to_file

Chuckles66, the resize function of CS2 is broken see posts in Adobe’s Photoshop Scripting forum for the work arounds. Im a CS1 user so I don’t know exactly how it misbehaves but think you need to set the ruler units to use pixels and apply the math to use resize with integer’s based on other units.
With some lines like this.

tell application "Adobe Photoshop CS"
	set UserPrefs to properties of settings
	set ruler units of settings to pixel units
	-- Do your stuff
	set ruler units of settings to ruler units of UserPrefs
end tell