Hi All
This problem stems from a Filemaker issue when exporting text files - FM exports vertical tabs as the line endings (asc 11). Easy-Peezy I thought - just replace them using an applescript - not so. It seems that OSX replaces a linefeed (asc 10) character with a carriage return (asc 13) when writing the data back to disc.
Check the script below - it opens a text file in the docs folder called “VT.txt” - this can be any scratch file with vertical tabs as the line endings. It replaces the vert tabs with linefeeds then writes them back to disc as the same file.
Sadly, you can use any character other than a linefeed and it works fine - use linefeed and it replaces it with a carriage return !!!
BTW, using OSX 10.5.7 (and tried using various versions before this with the same issue).
Also, I NEED it to be linefeeds
Someone out there has a simple fix to this problem I’m sure
TIA
Neil
– Issue with FMPro 9 substituting CRs for VTs
– This opens file VT.txt, replaces the VTs with LFs and resaves it
– © Neil D Gillies May 2009
– Coerce the path
set thePath to POSIX path of (path to documents folder from user domain)
set thePath to thePath & “VT.txt”
set thePath to POSIX file thePath
– read the file
open for access file thePath
set theText to read file thePath
close access file thePath
– Replace VTs with LFs
set cleanText to replaceVT(theText)
– Note the cleanText DOES contain linefeeds at this point so the problem is with the write routine to disc.
–set the clipboard to cleanText
my writeToFile(cleanText, thePath, false)
on replaceVT(theString)
set AppleScript’s text item delimiters to {ASCII character 11}
set textlist to text items of theString
set AppleScript’s text item delimiters to {ASCII character 10}
set newText to textlist as string
set AppleScript’s text item delimiters to {“”}
return newText
end replaceVT
on writeToFile(theData, targetFile, appendData)
try
set the targetFile to the targetFile as text
set the openTarget to open for access file targetFile with write permission
if appendData is false then set eof of the openTarget to 0
write theData to the openTarget starting at eof as string
close access the openTarget
return true
on error
try
close access file targetFile
end try
return false
end try
end writeToFile
Model: MAcBook Pro/10.5.7
AppleScript: 2.0.1
Browser: Safari 528.16
Operating System: Mac OS X (10.5)