Applescript,添加到文本文件底部

问题描述 投票:0回答:2

我正在为列表中的每个项目运行一个脚本,

每次它在文本文件的顶部添加一行,但我实际上需要更改该顺序,因此它写在最后一行的后面(在底部)

这是我当前的脚本

将 dataBackupFile 设置为(文本形式的桌面文件夹路径)&“Repport Data.txt” insertOnTop 从 informationOnThisAccount 到 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
text applescript
2个回答
2
投票

更换

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

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

0
投票

在文件底部添加很容易。

set mylog to open for access POSIX file "/path/to/file.txt" with write permission
write theData & theContent to mylog starting at eof
close access mylog
© www.soinside.com 2019 - 2024. All rights reserved.