Sample contents of a .txt file on my Mac:
This is sentence A.
This is sentence B.
This is sentence C.
This is sentence D.
This is sentence E.
I want to implement a subroutine, like this:
writeTextAtSpecificLine(("This is the newcomer sentence." & linefeed), 4)
so that, the text file would consequently look like this:
This is sentence A.
This is sentence B.
This is sentence C.
This is the newcomer sentence
This is sentence D.
This is sentence E.
I know that I can accomplish my desired result by making each line of the text file its own item in an AppleScript list
object, like so:
set theIndividualLinesOfTextFileAsList to paragraphs of (read theFilepathOfTxtFile)
I could then split the list
, based on the desired line number, and then add it all back together.
But, does a more efficient method exist?
My real .txt file is much longer than the sample content above.