I need to read/parse the contents of a rich text format (rtf), like a simple unicode text file (txt)
here’s a snipped:
set my_doc to choose file
set read_f to get (read file (my_doc as text))
set name_of to name of my_doc
set the_ls to {}
repeat with i from 1 to count of paragraphs in read_f
set this_p to (paragraph i of read_f)
display dialog (this_p & return as Unicode text)
--copy (this_p & return as Unicode text) to end of the_ls
end repeat
at some step of my script I want also to transform umlauts like ä, ü, ö into readable characters for a .txt (unicode) -file.
not shure if i got you right, but “TextEdit” can open RTF-Files …
So your solution could be something like this:
set rtffile to alias "Your:Path:to:Sample.rtf"
tell application "TextEdit"
open rtffile
my SaveAsUnicode(text of document 1)
end tell
on SaveAsUnicode(thetext)
set TextFile to (((path to desktop folder) as text) & "Sample.txt")
try
set the open_TextFile to open for access file TextFile with write permission
set eof of the open_TextFile to 0
write thetext to the open_TextFile as «class utf8» starting at eof
close access the open_TextFile
on error
try
close access file TextFile
end try
end try
end SaveAsUnicode
Hi Hans, thats right.
Yours is a nice solution.
I tried to evade “Text edit”, like i do for every tell-statement, to accelerate my scripts. But in some cases its necessary.
thanks for your time.