Manipulating PLAIN text on the clipboard

J. Landman Gay jacque at hyperactivesw.com
Tue Mar 9 00:23:35 EST 2004


On 3/8/04 6:38 PM, JonathanC at ag.nsw.gov.au wrote:

> I have some scripts that manipulate text on the clipboard (turn text to 
> uppercase/lowercase etc., add up a column of numbers, wrap/unwrap text 
> etc.) but I can't seem to get them to leave the text as PLAIN text.
> 
> Here's one of them:
> 
> on mouseUp
>   put the clipboardData["text"] into temp
>   set the clipboardData["text"] to wrap(temp,75)
> end mouseUp
> 
> No matter where I copy the text FROM, no matter what font and size it was, 
> it always ends up after pasting (assuming I paste it into an application 
> that supports styled text) as Lucida Grande, 11pt.
> 
> I'm sure the short script above is where the problem lies, but just in 
> case, here's the function it calls:
> 
> function wrap str,n
>   put "" into newStr
>   repeat with i=1 to the number of lines in str
>     put line i of str into para
>     if para = "" then
>       put return after newStr
>       next repeat
>     end if
>     put "" into newPara
>     repeat
>       put char 1 to n of para into lineTemp
>       if the length of lineTemp < n then
>         -- no more para
>         put return & lineTemp after newPara
>         exit repeat
>       end if
>       put the number of words in lineTemp into wordCount
>       put return & (word 1 to wordCount-1 of para) after newPara
>       delete word 1 to wordCount-1 of para
>     end repeat
>     delete char 1 of newPara -- return
>     put return & newPara after newStr
>   end repeat
>   delete char 1 of newStr -- return
>   return newStr
> end wrap
> 
> (I'm using Rev 2.1.2 on a PowerBook G4 running OS X 10.2.8.)

Looks like there may be a bug in the wrap function that causes it to go 
into an infinite loop, at least in some cases. It can get stuck at 
"delete word 1 to wordCount-1 of para". So maybe what is happening is 
that the repeat loop is going around in circles while you are pasting 
into another app, and what you paste is actually the original copied 
text rather than the modified text.

BTW, there is an example of a word-wrap script in the Cookbook in the 
Help docs.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com


More information about the use-livecode mailing list