---
title: "writeSelection(to:types:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsservicesmenurequestor/writeselection(to:types:)"
---

# writeSelection(to:types:)

Writes the current selection to the pasteboard.

## Declaration

```swift
optional func writeSelection(to pboard: NSPasteboard, types: [NSPasteboard.PasteboardType]) -> Bool
```

## Parameters

- `pboard`: The pasteboard to receive your data.
- `types`: An array of NSString objects listing the types of data that you should write to the pasteboard. You should write data to the pasteboard for as many of the types as you support.

## Mentioned in

Supporting Writing Tools via the pasteboard

## Return Value

Return Value true if your implementation was able to write one or more types to the pasteboard; otherwise, false.

## Discussion

Discussion A writeSelection(to:types:) message is sent to the first responder when the user chooses a command from the Services menu, but only if the receiver didn’t return nil to a previous validRequestor(forSendType:returnType:) message. After your method writes the data to the pasteboard, a remote message is sent to the application that provides the service the user requested. If the service provider supplies return data to replace the selection, the first responder will then receive a readSelection(from:) message.

## See Also

### Related Documentation

- [validRequestor(forSendType:returnType:)](appkit/nsresponder/validrequestor(forsendtype:returntype:).md)

### Working with Pasteboards

- [readSelection(from:)](appkit/nsservicesmenurequestor/readselection(from:).md)
