<<script>> doesn't understand the thefile message --on writing to file

Hi,

I have looked all around the forums and I can’t find anything about what I am looking for. I have a script that reads prefrences out of a text file. If the value in the text file as filepath then go on else choose a folder to replace it… this is where I get my error:


Tell application "Finder"
	set myPath to (container of (path to me)) as string
end tell
set accessfile to myPath & ".installs:prefs.txt"
set thefile to open for access accessfile with write permission
set filecontent to (read thefile as string)
--tests if file content is a directory else:
repeat
	display dialog "Do you want to install this?. Click 'More Info' for more info" buttons {"Don't Install", "More Info", "Install"} default button 3
	if button returned of result is "Install" then
		set filepath to (choose folder with prompt "Choose the directory where you want to install it" without invisibles) as string
              set eof of (thefile to 0) --get the error here...
		write (POSIX path of filepath) to thefile
		set original to POSIX path of myPath & ".installs/files/"
		do shell script "mv " & original & "   " & filepath
	--does stuff with other buttons
       end if
end repeat


there is more code i don’t if it’s impostant to add or not

thanks,
elictricocean

Browser: Safari 419.3
Operating System: Mac OS X (10.4)

here’s the problem, change

set eof of (thefile to 0) --get the error here...

to

set eof thefile to 0 --get the error here...

Thank you. that helped for that problem. now i get an error that says

Hi, elictricocean.

I don’t know what’s causing the new errors, but there are a couple of potential problems with the script as posted.

This isn’t actually one of the problems. Just to mention that it’s generally considered better nowadays to represent paths as Unicode text rather than as string. It preserves any Unicode-only characters that the user might have in his file/folder names.

On some systems, using a string (or Unicode) path as the parameter for open for access either doesn’t work or isn’t reliable. It’s better to use a file specifier or an alias ” ie. put the word file or alias in front of the path variable:

set accessfile to myPath & ".installs:prefs.txt"

set thefile to open for access file accessfile with write permission -- 'file accessfile'

The as in this line .

. isn’t a coercion but a parameter of the read command. It tells the command that the thefile contains string data which should be interpreted as such. However, later in the script, a POSIX path is written to thefile. POSIX paths are Unicode text, which has two bytes per character. If that’s what you’re reading here, it will need to be read as Unicode text:

set filecontent to (read thefile as Unicode text)

The errors you’ve been getting have been occurring while the file’s open for access with write permission. Unless you’ve trapped the errors with a try block, the access won’t have been closed and you won’t be able to open another one. The immediate way out of the problem would be to save the script and quit Script Editor, which should close any access it has open to the file. But in practice, everything that happens while a file’s open for access should be enclosed in a try block, so that, in the event of an error, the script keeps running long enough to execute a close access line (which should also be in the script).

Thanks i changed all of that. I also found out that the error comes up when I am actually writing to the file