0
votes

I am writing to a logfile in the ~/Library/Logs/DocumentLogs/ directory

I am doing this:

        --open and write logfile entries
        set writetoTheThing to open for access theFile with write permission
        write (logEntry & return) to writetoTheThing starting at eof

        close access (writetoTheThing)

and its working. Log files get written to....

The file is being opened "with write permission" and Get Info shows that I am the owner, etc.

However, the Event Log shows:

the Event: open for access alias "Macintosh HD:Users:lenny:Library:Logs:DocumentLogs:DocLog_2015_03.log" with write permission

The Event Result says: a privilege violations occurred (errAEPriviledgeError -10004)

How do I get around this?

TIA

2

2 Answers

0
votes

Do you have write permissions to the directory, and its parent directories?

I'd wrap a try — on error end try block around the write statement, with the error number, and then check that error number, if any, displaying it with display alert e & " : " & n.

If you are creating the file, then I'd also use starting at 0, but I can't see any difference in that at the moment (but I have a vague memory that starting at eof, starts at 1).

Maybe it helps if you restart Script Editor, due to a leaked filehandle, if you had some run time errors while devicing the handler.

0
votes

Thanks for all these good suggestions. However, I did get an answer from a colleague that I think is worth noting here. I did have permission and the eof wasn't an issue. The solution was to wrap the open, and close functions in a "tell me". This targets the scripting addition at the current process and avoids having the Finder report privilege violations.

This worked:

tell me set writetoTheThing to open for access theFile with write permission write (logEntry & return) to writetoTheThing starting at eof

close access writetoTheThing end tell

Mark at Script Debugger helped me out. His program is pure gold... and so is he with support. Thanks, everyone!