Hello all and sorry to ask something so childish, but it would take me days and days to perform this…
I need to copy the name of one text file, then add it as a suffix at the end of each line of this precise document (yes, working on a database with hundreds of different text files…)
I’ve tried to use bbedit function (add prefix-suffix), that works well manually, but I’m totally unable to put it straight on script…
that would be something like “copy filename”, open doc with bbedit, then prefix/suffix lines and put the copied filename in the box…
Can anyone loose some minutes to help me ?
Thanks in advance
set copyFileName to name of (info for (choose file))
set theFile to (choose file with prompt "Choose a file modify")
set theData to read theFile
set fileRef to (open for access file (theFile as Unicode text) with write permission)
set eof fileRef to 0
repeat with lineData in (paragraphs of theData)
write lineData & copyFileName & return to fileRef
end repeat
close access fileRef
set TheFolder to choose folder
tell application "Finder" to set theFiles to every file of TheFolder
tell application "BBEdit"
activate
repeat with aFile in theFiles
open aFile
set TheSuffix to name of document 1
add suffix document 1 suffix TheSuffix
close document 1 saving yes
end repeat
end tell
How many lines does your text file have? A quick way to do this is this if you have a lot of paragraphs:
get file name from file1
read file2
get pargraphs
set applescript’s text item delimiters to name and line ending
set list of pargraphs to string
overrwite file2
You should check what kind of line endings and text encoding the file has first.