Bellhop pasteboard Extension for Python Reference

 

Overview

The pasteboard extension defines methods that allow you to query the services pasteboard for its content, as well as put data back onto it. There are also a number of symbolic constants that are dynamically loaded into the Python interpreter that you can use to identify pasteboard data types, as well as targetting the Clipboard by name. These constants mimic those found in the Cocoa frameworks.

 

Pasteboard Data Types

The following global variables are automatically available to your Python scripts and are used to identify the various types of pasteboard data. You can use these symbolic names instead of creating new strings. For more information on the meaning of these types, see the Apple developer documentation for the NSPasteboard class.

Additionally, you can target the general clipboard by name using the NSGeneralPboard constant.

 

Method List for pasteboard Extension

The following methods are available in the pasteboard extension:

 

Method Descriptions for pasteboard Extension

pasteboard.gettypes(aPasteboard)
Returns an array of pasteboard types that are available on the services pasteboard identified by aPasteboard. The returned array will consist of strings from the list of global pasteboard type constants described earlier in the document.

 

pasteboard.declaretypes(aPasteboard, aTypeList)
Configures aPasteboard so that it can hold the pasteboard types in the array aTypeList, which should be a python list of strings representing a subset of the known pasteboard types (as outlined in the global pasteboard type constants appearing earlier in this document).

 

pasteboard.readdata(aPasteboard, aType)
Queries the services pasteboard aPasteboard for data of the given pasteboard type aType, and returns it as a Python string. aType should be one of the global constant pasteboard data types.

 

pasteboard.writedata(aPasteboard, aType, aData)
Writes aData, which should be a Python string object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call pasteboard.declaretypes() to configure the pasteboard for the proper types.

 

pasteboard.readstring(aPasteboard, aType)
Queries aPasteboard for data of the given pasteboard type aType, and returns it as a Python string. Note that this is no different from the pasteboard.readdata() function defined above; Python strings can also hold data.

 

pasteboard.writestring(aPasteboard, aType, aString)
Writes aString, which should be a Python string object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call pasteboard.declaretypes() to configure the pasteboard for the proper types.

 

pasteboard.readlist(aPasteboard, aType)
Queries aPasteboard for a list of objects of the given pasteboard data type aType. Returns the contents as a Python list object.

 

pasteboard.writelist(aPasteboard, aType, aList)
Writes aList, which should be a Python list object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call pasteboard.declaretypes() to configure the pasteboard for the proper types.

 

pasteboard.readdictionary(aPasteboard, aType)
Queries aPasteboard for a dictionary of the given pasteboard data type aType. Returns the contents as a Python dictionary object.

 

pasteboard.writedictionary(aPasteboard, aType, aDictionary)
Writes aDictionary, which should be a Python dictionary object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call pasteboard.declaretypes() to configure the pasteboard for the proper types.