problem reading file in xcode

In applescript editor this works fine

tell application "Finder" to set thefile to file "TestColorDB.csv" of desktop as text

my readFile(thefile)

on readFile(afile)
	set fileContents to read file afile using delimiter return -- this gives me a list of lines
end

When I put that subroutine in my applescript obj c project I get a error that says

2011-10-03 11:06:12.641 ConvertToColorBook[37735:1307] *** -[ConvertToColorBookAppDelegate readFile:]: Can’t make current application into type file. (error -1700)

Anybody have any idea’s?

Hi,

a AppleScript file specifier must be wrapped in a current application tell block,
the Finder is not needed to specify the path


set thefile to (path to desktop as text) & "TestColorDB.csv"
readFile(thefile)

on readFile(afile)
	tell current application to set fileContents to read file afile using delimiter return -- this gives me a list of lines
end readFile

Another option is to use a POSIX path. Then there’s one fewer “current application” to deal with.