<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSServicesMenuRequestor/writeSelection(to:types:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSServicesMenuRequestor(im)writeSelectionToPasteboard:types:"
  },
  "title" : "writeSelection(to:types:)"
}
-->

# writeSelection(to:types:)

Writes the current selection to the pasteboard.

```
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.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if your implementation was able to write one or more types to the pasteboard; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

A [`writeSelection(to:types:)`](/documentation/AppKit/NSServicesMenuRequestor/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:)`](/documentation/AppKit/NSResponder/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:)`](/documentation/AppKit/NSServicesMenuRequestor/readSelection(from:)) message.

## See Also

[`-  validRequestorForSendType:returnType:`](/documentation/AppKit/NSResponder/validRequestor(forSendType:returnType:))

Overridden by subclasses to determine what services are available.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)