Re: get contents from clipboard

2003-12-14 Thread John Delacour
At 5:01 pm +0900 11/12/03, Robin wrote:
late in on this one but you can treat the clipboard as a filehandle 
if you pipe to pbpaste and pbcopy :

open (FROM_CLIPBOARD, pbpaste|);
open (TO_CLIPBOARD, |pbcopy);
you can then do as you normally would for moving data to and from 
fle handles. See the typically useful-in-a-real-world-situation 
example script below
So far as I can see there is no way to use this useful technique with 
a clipboard containing Unicode text, for example Chinese or Greek 
text copied from TextEdit. Am I right?

JD




Re: get contents from clipboard

2003-12-14 Thread Joel Rees
On 2003.12.15, at 07:10  AM, John Delacour wrote:

At 5:01 pm +0900 11/12/03, Robin wrote:
late in on this one but you can treat the clipboard as a filehandle 
if you pipe to pbpaste and pbcopy :

open (FROM_CLIPBOARD, pbpaste|);
open (TO_CLIPBOARD, |pbcopy);
you can then do as you normally would for moving data to and from fle 
handles. See the typically useful-in-a-real-world-situation example 
script below
So far as I can see there is no way to use this useful technique with 
a clipboard containing Unicode text, for example Chinese or Greek text 
copied from TextEdit. Am I right?
Why do you think it won't work? Is there some irreversible munge 
applied to the pipes or the clipboard? Or is it the guessing game about 
being sure it was Unicode text?

reiisi



Re: get contents from clipboard

2003-12-14 Thread Steven Bach
On Dec 14, 2003, at 4:10 PM, John Delacour wrote:

At 5:01 pm +0900 11/12/03, Robin wrote:
late in on this one but you can treat the clipboard as a filehandle 
if you pipe to pbpaste and pbcopy :

open (FROM_CLIPBOARD, pbpaste|);
open (TO_CLIPBOARD, |pbcopy);
you can then do as you normally would for moving data to and from fle 
handles. See the typically useful-in-a-real-world-situation example 
script below
So far as I can see there is no way to use this useful technique with 
a clipboard containing Unicode text, for example Chinese or Greek text 
copied from TextEdit. Am I right?
That appears to be the case.  The man page for pbpaste/pbcopy 
explicitly refers to ASCII.

perl -e 'print `pbpaste`'
Tends to print ?s for unicode characters or nothing at all depending on 
the shell.

Putting unicode on the clipboard and doing 'pbpaste|pbcopy' 
consistently mangles the contents of the clipboard in bash, tcsh, and 
zsh.

Looks like a good candidate to file a bug against.

Steven



Re: get contents from clipboard

2003-12-14 Thread Doug McNutt
It used to be, back in the days of Apple Classic, that the clipboard contained several 
copies of the stuff that was placed there.  Each copy was identified by one of those 
four character type codes that are now deprecated in OS neXt.

pbpaste, as a tool, does not allow tor an argument for selecting which information 
type is to be selected.

Does it take the first type encountered?

Does it default to TEXT, meaning the UTF-8 copy will be ignored?

Does it read the UTF-8 version as though it were simple text?

Are the type codes no longer supported in OS neXt?

And, for that matter, what is the difference between the pasteboard and the clipboard 
anyway? Some NeXT documentation refers to the pasteboard as equivalent to the current 
selection, copied or not.

-- 
--  There are 10 kinds of people:  those who understand binary, and those who don't 
--


Re: get contents from clipboard

2003-12-14 Thread Andrew M. Langmead
On Dec 14, 2003, at 9:15 PM, Doug McNutt wrote:

pbpaste, as a tool, does not allow tor an argument for selecting which  
information type is to be selected.
The pbpaste command seems to know about three types, ascii,   
postscript, and rtf,
and by default it will try to retrieve the clipboard in that order. The  
initial
attempt to retrieve the clipboard in a format can be adjusted with the  
-Prefer
command line argument, (from what I can see from  
http://www.vorlesungen.uni-osnabrueck.de/informatik/shellscript/Html/ 
Man/_Man_NeXT_html/html1/pbcopy.1.html
the option has existed since the NextSTEP days.

The underlying implementation is undoubtedly built on the
NSPasteboard object  
http://developer.apple.com/documentation/Cocoa/Reference/ 
ApplicationKit/ObjC_classic/Classes/NSPasteboard.html which has an  
option to represent the clipboard
data as an NSString. Oddly enough, NSStrings can hold Unicode strings.  
The NSString
component representation of the clipboard is probably turned into text  
to be output
from pbpaste via a method like -lossyCString.



Re: get contents from clipboard

2003-12-11 Thread Robin
late in on this one but you can treat the clipboard as a filehandle if 
you pipe to pbpaste and pbcopy :

open (FROM_CLIPBOARD, pbpaste|);
open (TO_CLIPBOARD, |pbcopy);
you can then do as you normally would for moving data to and from fle 
handles. See the typically useful-in-a-real-world-situation example 
script below below which uses this technique - copy a word to the 
clipboard, run the script and it will place a backewards version on the 
clipboard to be pasted where ever.

#!/usr/bin/perl -w

use strict;
my($data,$word);
my(@letters);
open (FROM_CLIPBOARD, pbpaste|);
open (TO_CLIPBOARD, |pbcopy);
$data=FROM_CLIPBOARD;

if ($data){ $word=$data ;}
else { $word = forwards; }
@letters=split(//,$word);

print TO_CLIPBOARD reverse(@letters),\n;

close (FROM_CLIPBOARD);
close (TO_CLIPBOARD);


On Tuesday, November 25, 2003, at 09:25  am, Jay Young wrote:

Is it possible to get the contents from the clipboard with Perl?  
Looking in a book I see - Win32::Clipboard

but is it possible to get it on the Mac in OS 10.3?

Thanks.

Jay




Re: get contents from clipboard

2003-11-24 Thread John Delacour
At 6:25 pm -0600 24/11/03, Jay Young wrote:
Is it possible to get the contents from the clipboard with Perl? 
Looking in a book I see - Win32::Clipboard

but is it possible to get it on the Mac in OS 10.3?
If you just want the text, then either of these will do:

print `osascript -e 'the clipboard'` ;

#or

print `pbpaste` ;

JD