Re: Unicode text and the annoying relic called "styled text"
Re: Unicode text and the annoying relic called "styled text"
- Subject: Re: Unicode text and the annoying relic called "styled text"
- From: Pat Stanford <email@hidden>
- Date: Fri, 24 Dec 2004 10:47:46 -0800
So is there a way to get a "string" without style information onto the
clipboard?
Thanks,
Pat
Pat Stanford
Coviana, Inc.
email@hidden
On Dec 23, 2004, at 10:11 PM, Christopher Nebel wrote:
On Dec 21, 2004, at 3:18 PM, Scott Babcock wrote:
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.
Let's get one thing clear here: AppleScript is not lying to you.
"String" doesn't mean what you think it means. There has never been
any guaranteed correspondence between AppleScript value types and
clipboard data flavors (or Apple Event Manager types, which are a
superset of them.) "String" values may or may not include style
information. This is documented (albeit not very clearly) in the
Language Guide.
If the goal is simply to get a plain text flavor onto the clipboard,
then what you ought to do is this:
set utxt to "Foo" as Unicode text
set |TEXT| to utxt as string
set the clipboard to |TEXT|
"set the clipboard" is smart enough to break the styled text into
separate 'TEXT' and 'styl' flavors, so your target application should
get what it wants, unless it's *really* stupid. Unfortunately, "set
the clipboard" is not smart enough to do this transformation if the
styled text is merely one element of a record; there's a bug filed on
that.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
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