At 9:13 am +0100 19/03/01, Detlef Lindenthal wrote:

>Ronald J Kimball wrote:
>
>>  Still, I don't know why it would be preferable to
>>  write a solution with these obscure limitations (which will be difficult to
>>  debug if they're ever hit) when there's another approach which is correct
>  > and robust.

So's we're all singing from the same song sheet, here's a sample
return from LMGetScrapHandle (it probably won't travel well, but here
goes):

TEXTThis is about styled
textstylFISH(FISHÄ
GenevaSOUP

And there the problems start. The ONLY other things MacPerl can tell
you about the clipboard are the three 'LMGetScrap*' functions, for
size, count and state, none of which is helpful. (The fish soup is
WASTE BTW...).

>From my point of view: Because so far no pioneer showed us that other
>correct and robust approach. Are you thinking of AppleScript?
>And combined with that approach I could do text replacing using
>Perl Regex? -- But how?
>Can you provide sample code?
>Perl is quick; is that other approach quick too?

My own view now, with apologies for having started this LowMem hare,
is that AppleScript is the only reliable way of getting at the
'style', 'PICT', 'snd ' and application-specific clipboard elements.
This will do it quite quickly:

#!perl

use Mac::AppleEvents;

my $evt = AEBuildAppleEvent('misc', 'actv', 'sign', 'MACS', 0, 0, "")
                                                            or die $^E;
my $rep = AESend($evt, kAEWaitReply) or die $^E;

$evt = AEBuildAppleEvent('Jons', 'gClp', 'sign', 'MACS',  0, 0,
                          "rtyp:type(reco)") or die $^E;

$clip = AESend($evt, kAEWaitReply) or die $^E;

$str = AEPrint($clip);

AEDisposeDesc $evt;
AEDisposeDesc $clip;

It would be nice to get AppleEvents to dismember the record perhaps,
but that can be done with absolute safety by MacPerl, so it is only
an academic matter. I can't find a way of writing the AppleEvent to
do this. Any suggestions?

>What I would like to do: Automatic editing of styled text of a FileMaker
>database with thousands of articles, with help of regex. Or of a pile of
>styled text files opened by TexEdit.
>Does your approach approach this?

I have a script (using the above AE) which decodes the 'styl' and
returns the contents in a hash. It's a bit long to add here, and
maybe interest in it might not be as wide as it's long, but if anyone
wants it I'll be happy to send it of course. Would it be worth making
into a module I wonder?

As to whether it would cope with "automatic editing etc..." I'm not
sure. How were you thinking of tackling this?

Alan Fry

Reply via email to