I’ve successfully run a script on Mac OS 8.6 that seems to not run on OS 9.2.2. In fact, a lot of my scripts seem to not work.
Is there anything basic that has changed with Applescript that would make this occur? (I’ve been away from scripting for quite a few years and was never much of an expert to begin with.)
The command that used to work is:
set MyFile to “cpy files”
open for access file MyFile with write permission
set eof file MyFile to 0
I now get an error message “File cpy files wasn’t found”
Nothing has changed from before except the OS.
Thanks for any help you can give or any phone number where help may be available.
Mark
Model: G4 466 Power Mac
AppleScript: 1.7
Browser: Internet Explorer 5.17
Operating System: Mac OS 9.2.x
set MyFile to "cpy files"
open for access file MyFile with write permission
set eof file MyFile to 0
Mark;
I think that either the definition of MyFile command should have a location in it - a path to where the file is supposed to be, and in addition leave out the word file Example:
set MyFile to (path to desktop as string) & "cpy files"
open for access MyFile with write permission
set eof file MyFile to 0
-- do stuff
close access MyFile -- don't forget this line.
I disagree with Adam’s advice to leave out the word ‘file’. The file read/write commands sometimes work with just the string, but I believe it’s caused problems in some versions of AppleScript. In any case, it’s always good to remind oneself that there’s a difference between a string and a file specification
I totally agree about using the entire path to the file though. I’d also recommend using the access reference returned by ‘open for access’ rather than keep using the file specification. It’s faster and can avoid errors in some instances. Speaking of errors, it’s a good idea to use a ‘try’ block too, to ensure that the file’s closed again even if anything goes wrong.
set MyFile to (path to desktop as string) & "cpy files"
set fRef to (open for access file MyFile with write permission)
try
set eof fRef to 0
-- do stuff
on error msg
display dialog msg buttons {"OK"} default button 1
end try
close access fRef -- don't forget this line.