Photoshop CS5+Applescript=File some object wasn’t found." number -43

I pieced together a script that determines which side of an image is longest (horizontal or vertical) and runs the corresponding horizontally or vertically oriented photoshop action. With CS5 I keep getting the same error “error “Adobe Photoshop CS5 got an error: File some object wasn’t found.” number -43” Adobe website says it has something to do with Photoshop and the finder having different definitions of “alias” but I still don’t know how to fix it.
I’m an applescript novice at best and I don’t even remember how I put this one together. Please help!


set tempFolderName to "Temp"
set inputFolder to choose folder

tell application "Finder"
	set filesList to files in inputFolder
	if (not (exists folder ((inputFolder as string) & tempFolderName))) then
		set outputFolder to make new folder at inputFolder with properties {name:tempFolderName}
	else
		set outputFolder to folder ((inputFolder as string) & tempFolderName)
	end if
end tell

tell application "Adobe Photoshop CS5"
	set display dialogs to never
	close every document saving no
end tell

repeat with aFile in filesList
	
	set fileIndex to 0
	
	tell application "Finder"
		-- The step below is important because the 'aFile' reference as returned by
		-- Finder associates the file with Finder and not Photoshop. By converting
		-- the reference below 'as alias', the reference used by 'open' will be
		-- correctly handled by Photoshop rather than Finder.
		set theFile to aFile as alias
		set theFileName to name of theFile
	end tell
	
	tell application "Adobe Photoshop CS5"
		
		open theFile
		
		set docRef to the current document
		set docHeight to height of docRef
		set docWidth to width of docRef
		
		if (docHeight > docWidth) then
			do action "Master v1 w/Proof Rotate" from "AWSP"
		end if
		if (docHeight < docWidth) then
			do action "Master v1 w/Proof" from "AWSP"
		end if
	end tell
end repeat

try to replace these two lines in your script

set theFile to aFile as alias

replace with: set theFile to aFile as string

and

open theFile

replace with : open alias theFile

Thanks for the help. I tried your suggestion but I ended up with another issue after I replaced the text.

Result:
error “Can’t get name of "Chicago RAID:2010 AWSP:Weddings:Bella:20100828PaigeColeman:test:IMG_3814.JPG".” number -1728 from name of “Chicago RAID:2010 AWSP:Weddings:Bella:20100828PaigeColeman:test:IMG_3814.JPG”

The “name” was highlighted with the error in this section of the script


set theFile to aFile as string
		set theFileName to name of theFile
	end tell

Swap the orser of those two “set” lines.

Switching the two lines as suggested from this


set theFile to aFile as string
set theFileName to name of theFile

to this


set theFileName to name of theFile
set theFile to aFile as string

gave me this error-

The variable theFile is not defined.

Make it:

set theFileName to name of aFile

WHOOOOOOOHOOOOOOO!!!

It’s a small script but it save me lots of time. This script and 2 photoshop actions kicks out 5 different sizes/colors for proof prints, online gallery, facebook, blog and client cd. 5 sizes x roughly 800 images per wedding x 25-30 weddings a year= a lot of images.

Thank you thank you thank you.