textapplescript

Applescript, add to bottom of text file


I'm running a script for each item of a list,

each time it's adding a line to the top of a text file, but I actually need to change that order, so it write behind the last one (at the bottom)

here is my current script

et dataBackupFile to (path to desktop folder as text) & "Repport Data.txt" insertOnTop from informationOnThisAccount into dataBackupFile

on insertOnTop from theData into theFile
    try
        set fileDescriptor to open for access file theFile with write permission
        if (get eof fileDescriptor) > 0 then
            set theContent to read fileDescriptor as «class utf8»
        else
            set theContent to ""
        end if
        set eof fileDescriptor to 0
        write (theData & theContent) to fileDescriptor as «class utf8»
        close access fileDescriptor
        return true
    on error
        try
            close access file theFile
        end try
        return false
    end try
end insertOnTop

Solution

  • Replace

    set eof fileDescriptor to 0
    write (theData & theContent) to fileDescriptor as «class utf8»
    

    with

    write (theData & theContent) to fileDescriptor as «class utf8» starting at eof