Wednesday, 12 March 2014

Apple: Add A Line Of Text Above The Existing First Line Of A Text File With AppleScript

The AppleScript below allows you to add a line of text ( eg. This is line 2 ) above the existing first line of a text file named test.txt in a folder called OUTPUT.
try

    set theFile to (((path to desktop) as text) & "OUTPUT:" & "test.txt") as alias

    set N to open for access theFile with write permission

    get eof N

    if result > 0 then

        set theText to read N

        set eof N to 0

        write "This is line 2" & return & theText to N

    end if

    close access N

end try

Reference:
Applescript: to open a file, add a line of text at the top, and then close the file.
https://discussions.apple.com/message/18858350#18858350

No comments:

Post a Comment