I have been trying to write a script that will turn hexadecimal into plain text. I have been using textedit and am having trouble. I have been fooling around with the following but to no avail.
set every word where it is "’" to "'"
Am i using the wrong class or does anyone have any suggestions?
tell application “TextEdit”
launch
activate
make new document at front with properties {name:“Test Document”}
set text of front document to “The rain in Spain falls mainly in the plain.”
delay 1
set every word of front document whose it is “in” to “test”
end tell
Thanks for the script, but i can’t seem to get it to do what i want it to do. I’ll outline the entire problem i am faced with.
I need a quick and easy way to convert a lot of text from unicode to plain text. I have come up with a way of converting it to a hexidecimal format so all the apostrophes get turned into & #8217; using javascript. I then need a way to turn this into normal plain text so it is searchable in xml.
As you can probably tell, i am fairly new to applescript, but if there is a quick script to do all of that, and you know where i can find it, it would be much appreciated.
The script that i have come up with so far is:
display dialog "Paste the text here" default answer ("here") buttons {"OK"} default button 1
set the this_text to the text returned of the result
tell application "TextEdit"
activate
close every document saving no
make new document at the beginning of documents
set the name of window 1 to "Converted Text"
set the text of the front document to ¬
this_text
tell the text of the front document
set the size to 12
set every word where it contains "& #8217;" to "'"
end tell
end tell
Unfortunately this doesn’t help me as I don’t know enough applescript to understand (and therefore adapt) the code.
I have started coming at the problem from a different approach, trying to sort it all out in applescript, but it as yet hasn’t worked.
Any ideas why?
display dialog "Paste the text here" default answer ("here") buttons {"OK"} default button 1
set the this_text to the text returned of the result as string
on AsText(str)
--coerce Unicode or other text to styled string to plain text
try
return (((str as string) as record)'s «class ktxt»)
end try
return str -- if plain text to begin with
end AsText
tell application "TextEdit"
activate
close every document saving no
make new document at the beginning of documents
set the name of window 1 to "Converted Text"
set the text of the front document to my AsText(this_text)
end tell
Perhaps this helps. Let’s imagine you have a file called “a.txt”, whose contents are Unicode text “a” (hex “FE FF 00 61”). And you wanna convert it to plain ascii. Then:
And now you have the same file (“a.txt”) with contents “a” (hex “61”).
Is this similar to what you need?
Getting closer, but this one simply converts all of the text to question marks. To be honest I think what i’m trying to do is out of my league a bit.
It’s for dumping straight into a webpage, but the apostrophes and quotation marks all turn into something else while most of the text remains unchanged.
very annoying, don’t worry if you can’t think of something that does it all magically, my brain has gone to mush thinking about it.