Skip navigation

Error while wrting data into file using Applescript

467 Views 6 Replies Latest reply: Dec 19, 2012 8:00 PM by madhusudhanjr RSS
madhusudhanjr Calculating status...
Currently Being Moderated
Dec 19, 2012 7:08 AM

am using the below script for writing the file, but sometimes am getting errors like mentioned below, pls suggest..


set filepath to POSIX path of "Macintosh HD:Library:Application Support:Macromedia:mms.cfg"
    tell application "System Events"
        if file filepath exists then
            set myFile to open for access file filepath with write permission
            set fileData to read myFile
            set eof myFile to 0
            write "blah blah" to myFile
            close access myFile
            return "File Not Found"
        end if
    end tell
on error
    return false
end try



"Network file permission error." number -5000 from file "Macintosh HD:Library:Application Support:Macromedia:mms.cfg"


Also some times i will get this error, am unable to close the opened file


"File file Macintosh HD:Library:Application Support:Macromedia:mms.cfg is already open." number -49 from file "Macintosh HD:Library:Application Support:Macromedia:mms.cfg"


When i tried to close the ofile am getting this eror:


on openAFile(filepath)
        set fp to open for access filepath with write permission
    on error errstr number errNum
        if errNum = -49 then
            close access filepath
            set fp to open for access filepath with write permission
            display dialog errstr
            return false
        end if
    end try
    return fp
end openAFile
set pointer to openAFile("Macintosh HD:Library:Application Support:Macromedia:mms.cfg"
set fileContents to read pointer




"Can’t make \"Macintosh HD:Library:Application Support:Macromedia:mms.cfg\" into type file." number -1700 from "Macintosh HD:Library:Application Support:Macromedia:mms.cfg" to file

Mac OS X (10.7.4)
  • twtwtw Level 5 Level 5 (4,580 points)

    if you're using HFS (colon-delimited) file paths, then you always have to prefix it with the file or alias keywords.  If you don't, Applescript will see it as a plain sting rather than a file path.  You can use POSIX (slash-delimited) paths directly.  examples:


    set filepath to POSIX path of file "Macintosh HD:Library:Application Support:Macromedia:mms.cfg"


    set fp to open for access alias filePath with write permission

  • Frank Caggiano Level 7 Level 7 (22,770 points)

    Well error -49 is that the file is already open. So if you run the script and it opens the file but you get the error -5000 and the script aborts then when you run the script again the file is open as far as the editor is concerned and you get the -49 error.


    The only way I know to clear that is to quit he script editor and reopen it. That should eliminate the -49 error Not sure what the -5000 is telling you, trying to look it up now.


    Message was edited by: Frank Caggiano - -5000 is path or permission problem on the file

  • twtwtw Level 5 Level 5 (4,580 points)

    Those were intended as examples, not implementations.  You shouldn't generally use the alias keyword with a slash-delimited path.  why don't you show he current version of the script (so I can see exactly what you did).


    oh, and **** me for an old ****, but please: the English sentance is "I implemented your changes but the problem still exists".  I don't mind that stuff in texting, but on a public forum it makes you look like you topped out at a third-grade education.   Not at all inspiring...

  • Austin Kinsella1 Level 6 Level 6 (11,505 points)
    Currently Being Moderated
    Dec 19, 2012 8:48 AM (in response to twtwtw)

    First fix your own - it is sentence not sentance. You don't know whether the OP has English as a first language, never mind the education level completed.


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.