Pasteboard Module Reference
Overview
The Pasteboard module defines functions that allow you to query the services pasteboard for its content, as well as put data back onto it. Additionally, the Pasteboard module defines a number of symbolic constants that you can use to identify pasteboard data types, as well as targetting the Clipboard by name.
Pasteboard Data Types
The following global variables are automatically available to your Ruby 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.
NSStringPboardType
NSTabularTextPboardType
NSFilenamesPboardType
NSFileContentsPboardType
NSRTFPboardType
NSRTFDPboardType
NSPostScriptPboardType
NSPDFPboardType
NSHTMLPboardType
NSURLPboardType
NSTIFFPboardType
NSPICTPboardType
NSColorPboardType
NSRulerPboardType
NSFontPboardType
NSVCardPboardType
Additionally, you can target the general clipboard by name using the NSGeneralPboard
constant.
Pasteboard Module Method List
The following methods are available in the Pasteboard module:
- Pasteboard.getTypes(aPasteboard)
- Pasteboard.declareTypes(aPasteboard, aTypeList)
- Pasteboard.readData(aPasteboard, aType)
- Pasteboard.writeData(aPasteboard, aType, aData)
- Pasteboard.readString(aPasteboard, aType)
- Pasteboard.writeString(aPasteboard, aType, aString)
- Pasteboard.readArray(aPasteboard, aType)
- Pasteboard.writeArray(aPasteboard, aType, anArray)
- Pasteboard.readHash(aPasteboard, aType)
- Pasteboard.writeHash(aPasteboard, aType, aHash)
Pasteboard Module Method Descriptions
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 an array of strings representing a subset of the pasteboard types defined 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 Ruby String. aType should be one of the pasteboard data types.
Pasteboard.writeData(aPasteboard, aType, aData)
Writes aData, which should be a Ruby String object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call 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 Ruby String. Note that this is no different from the readData() function defined above; Ruby strings can also hold data.
Pasteboard.writeString(aPasteboard, aType, aString)
Writes aString, which should be a Ruby String object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call declareTypes() to configure the pasteboard for the proper types.
Pasteboard.readArray(aPasteboard, aType)
Queries aPasteboard for an array of objects of the given pasteboard data type aType. Returns the contents as a Ruby Array object.
Pasteboard.writeArray(aPasteboard, aType, anArray)
Writes anArray, which should be a Ruby Array object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call declareTypes() to configure the pasteboard for the proper types.
Pasteboard.readHash(aPasteboard, aType)
Queries aPasteboard for a hashtable of the given pasteboard data type aType. Returns the contents as a Ruby Hash object.
Pasteboard.writeHash(aPasteboard, aType, aHash)
Writes aHash, which should be a Ruby Hash object, to aPasteboard with the pasteboard data type aType. Before calling this function, be sure to call declareTypes() to configure the pasteboard for the proper types.