• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unicode text and the annoying relic called "styled text"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unicode text and the annoying relic called "styled text"


  • Subject: Re: Unicode text and the annoying relic called "styled text"
  • From: Christopher Nebel <email@hidden>
  • Date: Thu, 23 Dec 2004 22:11:27 -0800

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: This email sent to email@hidden
  • Follow-Ups:
    • Re: Unicode text and the annoying relic called "styled text"
      • From: Pat Stanford <email@hidden>
References: 
 >Unicode text and the annoying relic called "styled text" (From: "Scott Babcock" <email@hidden>)

  • Prev by Date: Re: choose url
  • Next by Date: FileMaker "current Record"
  • Previous by thread: Re: Unicode text and the annoying relic called "styled text"
  • Next by thread: Re: Unicode text and the annoying relic called "styled text"
  • Index(es):
    • Date
    • Thread