Re: set the clipboard not available in in some apps (like Word)
Re: set the clipboard not available in in some apps (like Word)
- Subject: Re: set the clipboard not available in in some apps (like Word)
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 14 Dec 2004 13:58:51 -0800
Yes, that's great, Scott. Chris Nebel proposed another version of the same
thing. Chris's version - setting the clipboard to a record that contains
both non-empty text and Unicode text properties - is probably better for
Joseph's uses. Instead of setting the text (or string) property to "", set
it to (utxt as string). In your particular example - a snowman and smiley -
it wouldn't help, and for pasting into Word it will make no difference since
Word will use the Unicode text property anyway. But for the general purpose
of being able to copy from an AS Studio text box - where the text will
always be Unicode but usually regular characters (that will often have a
text equivalent) not Wingdings - and paste into _any_ text app, not just
Word but also apps that don't do Unicode, having as good a value for text
(string) flavor on the clipboard is obviously better than "".
set the clipboard to {text:(s as string), Unicode text:s}
For AS, it would be good if the Standard Additions dictionary entry for 'set
the clipboard' - plus any documentation for it that may ever be published -
were updated to reflect that you can set it to a record, and tell us what
all the possible property labels (text, Unicode text, styled text, what
else?) of this record can be. And I still think it would be a good idea for
AppleScript to make a default TEXT flavor when a more exotic variety is
enabled by the class of object being set when a record is not used.
--
Paul Berkowitz
> From: Scott Babcock <email@hidden>
> Date: Mon, 13 Dec 2004 18:27:12 -0800
> To: AppleScript-Users <email@hidden>
> Subject: RE: set the clipboard not available in in some apps (like Word)
>
> OK, here's a much more useful explanation, and a much easier
> work-around.
> There is a bug in the 'paste' implementations of standard dialog text
> fields and Word 2004, among others, which causes fits when the only
> content on the clipboard is Unicode text. The work-around is to put a
> string-format entry in the clipboard, too. It doesn't matter what the
> content of this second entry is; it won't actually be used. It just
> wakes up the code that processes the clipboard content and enables it to
> accept the Unicode text entry. Here's a much easier way to accomplish
> this than my previous suggestion (you'll need to replace the fake
> guillemets with the real thing):
>
> set utxt to <<data utxt2603263A>>
> set reco to {Unicode text:utxt, string:""}
> set the clipboard to reco
>
> Paste to your heart's delight. This content will insert a snowman and a
> smiley in Word 2004 and in standard dialog text fields.
>
> -----Original Message-----
> From: Scott Babcock
> Sent: Monday, December 13, 2004 3:55 PM
> To: 'email@hidden'
> Subject: Re: set the clipboard not available in in some apps (like Word)
>
> Another work-around is to use Perl to create a clipboard data record
> with both 'TEXT' and 'utxt' elements. In AppleScript, write your Unicode
> string to a file. Read this file into Perl, construct a record with
> 'TEXT' and 'utxt' elements, write this record to another file, read this
> file as a record in AppleScript, and set the clipboard to this record.
> I've done this myself, setting the content of each element to the same
> UTF-16 (Unicode text) data. This clipboard content works in Word and in
> other instances where having only 'utxt' content fails, like standard
> dialog text fields.
>
> -----Original Message-----
> Date: Mon, 13 Dec 2004 09:50:53 -0800
> From: Paul Berkowitz <email@hidden>
> Subject: Re: set the clipboard not available in in some apps (like
> Word)
> To: AppleScript-Users <email@hidden>
> Message-ID: <BDE3167D.80D68¾email@hidden>
> Content-Type: text/plain; charset="US-ASCII"
>
> On 12/12/04 1:12 PM, "Joseph Weaks" <email@hidden> wrote:
>
>>
>>> ...But it's really to do with
>>> Word (or Office) having its own clipboard. They'll communicate
> one-way
>>> but
>>> not the other way. We've seen that setting the clipboard to a string
>>> via
>>> AppleScript somehow is transferable to Word's clipboard, so it
> pastes.
>>> Unicode doesn't transfer from the system clipboard to Word's (I
> expect
>>> it's
>>> still using an old-fashioned method of getting styles).
>>
>> I am not queazy about calling this a bug! At best, it's incomplete and
>> poor Unicode implementation.
>
> It's been confirmed by MS as a recently discovered bug. What's happening
> is
> this: legacy code in Word is looking just for 'TEXT' (plain text)
> "flavor"
> on the clipboard to see whether the clipboard's state is enabled or not,
> rather than also checking 'UTXT' (Unicode text) flavor too. Normally
> this is
> not an issue, since every application that puts UTXT (or styled text or
> graphics plus text, etc.) on the clipboard _also_ puts 'TEXT' version
> there
> too. That's why it works fine in the UI. It's _only_ AppleScript's 'set
> the
> clipboard' which doesn't bother to take the precaution of putting a
> plain
> text version for safety.
>
> Frankly, IMO, this is also a "bug" - legacy code in Standard Additions
> that
> has not been brought up to date - that 'set the clipboard' does not take
> this same elementary precaution that all applications take. In any case,
> a
> later version of Word will check all flavors on the clipboard.
>
> If you wanted, you could get around this in a Studio app by using 'call
> method' with NSPasteboard methods to get your text box or text field
> data to
> the clipboard, rather than 'set the clipboard'. I had to do that in one
> of
> my Studio apps in order to get attributed strings (colored formatted
> text)
> with graphics up there. There's a default for always including the plain
> text version, and that would trigger Word's clipboard check.
> NSPasteboard
> methods can get a bit complicated - and of course we're mostly using
> Studio
> so as not to have to learn all that Objective C stuff. But - not for the
> first time - it tends to work better...
>
> Anyway - if Chris N. is reading here - this is a request for the
> Standard
> Addition's 'set the clipboard' to always include a plain text 'TEXT'
> default
> flavor _even when_ the text being specified is Unicode text. I can bug
> this
> if need be.
>
> --
> Paul Berkowitz
> _______________________________________________
> 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
>
_______________________________________________
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