[Pythonmac-SIG] Copying to clipboard (pasteboard)

Bob Ippolito bob at redivi.com
Thu Mar 24 16:24:31 CET 2005


On Mar 24, 2005, at 9:57 AM, Jeremy Conlin wrote:

>> I figured out how to do this with a lot of trial and error.  You can 
>> use Carbon or AppKit/Foundation.
>>
>> -------------------------------------------------
>> import Carbon.Scrap, AppKit, Foundation
>>
>> def clipcopy(arg):
>> 	Carbon.Scrap.ClearCurrentScrap()
>> 	scrap = Carbon.Scrap.GetCurrentScrap()
>> 	scrap.PutScrapFlavor('TEXT', 0, arg)
>>
>>
>
> That worked!  Thanks a bunch.
> (Now I get to show what kind of a newbie I am.)  Why should I put this 
> into a class?  Is it just better programming practice?  I suppose the 
> answer may depend on what the script does and how complicated it is.
>
> Also, where can I find documentation on this?  I tried Python's help, 
> but it offered very little.

For any of the Carbon.* functions you need to look in Apple's 
documentation or the headers for the C version, and then more or less 
just guess how it would work from Python.  Those wrappers are 
automatically generated and nobody has documented them.

I'd recommend avoiding the Carbon stuff whenever possible and using 
PyObjC and Cocoa instead.  The translation from Objective-C to Python 
is straightforward and maintained, the documentation (both Apple's and 
PyObjC's) is better, the APIs are generally cleaner and more obvious to 
begin with, amongst other things.

-bob



More information about the Pythonmac-SIG mailing list