Unicode text and the annoying relic called "styled text"
Unicode text and the annoying relic called "styled text"
- Subject: Unicode text and the annoying relic called "styled text"
- From: "Scott Babcock" <email@hidden>
- Date: Tue, 21 Dec 2004 15:18:57 -0800
- Thread-topic: Unicode text and the annoying relic called "styled text"
I ran into an issue with a UI script in which I stuff the clipboard with
text and paste it into a dialog text input field. The string I started
from was Unicode text, but all of the characters in it could be
represented in 7-bit ASCII. I had code that did something like this:
set utxt to "Foo" as Unicode text
set |TEXT| to utxt as string
set the clipboard to {string:|TEXT|, Unicode text:utxt}
When I tried to paste this content, I got a very short string of
invisible "stuff" in the input field. To figure out what was going on, I
extracted the content of the clipboard as a record:
set clipData to the clipboard as record
--> Unicode text:"Foo", styled text:"Foo"
Styled text?!!! Where did that come from? Come to find out, the attempt
to coerce Unicode text to string actually returned styled text. By
design (a gross misapplication of the word), you can't directly tell
when you have styled text, because AppleScript lies and says you have a
string. This is described in Matt Neuburg's book, "AppleScript, The
Definitive Guide".
Here's what I had to do to get what I wanted:
set utxt to "Foo" as Unicode text
set |TEXT| to utxt as string
try
set styledText to |TEXT| as record
set |TEXT| to <<class ktxt>> of styledText
end try
set the clipboard to {string:|TEXT|, Unicode text:utxt}
The attempt to coerce |TEXT| to a record will fail if it's not styled
text, which is fine since that means that it's already a string. With
the addition of the 'try' block, I seem to have a complete, albeit
crufty, solution.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden