I’m writing a script that saves a text file with a few records in it. The first time it executes correctly, but each successive time, I get an error message that says that the file was not opened with write permissions. Here’s the code that deals with reading in the data when the document is opened:
on readFile(fileList) set fileExists to false if fileList contains dataFileName then set fileExists to true if fileExists then set inputFile to open for access file dataFile set eof_value to get eof of inputFile if eof_value > 0 then set jobData to read inputFile as list else close inputFile return false end if close inputFile return true else return false end if end readFile
And this is where it writes to the file:
on saveFile() set outputFile to open for access file dataFile with write permission set eof of outputFile to 0 write jobData to outputFile as list close outputFile end saveFile
I was thinking that it was a permissions error, because I’m running it off of a server, but I can’t figure out how to set the permissions, and I honestly don’t think that’s what it is because I copied the text file local, set the permissions to read/write for everyone, and then replaced the version on the server. But I still had the same problem.
One more thing. The text file that is written is an invisible file (I named it .jobdata), so that the users will only see the script. If anyone has the time to take a look at it, I could post the whole script, but it’s about 150 lines, so I thought I’d try to trim it down for the post.
Thanks for any help, I really appreciate it. I’m getting really frustrated!
PS. just to be clear, here’s the definitions for some of the variables… jobData, dataFileName and dataFile are globals:
set ASTID to AppleScript's text item delimiters set text item delimiters to ":" set dataFile to (text items 1 through -3 of (path to me as text) as string) & ":" & dataFileName set fileList to list folder (text items 1 through -3 of (path to me as text) as string) set text item delimiters to ASTID