How do I implement a _global_ copy command for my app?

I would like to implement a global copy command for my app. The code below is an attempt at achieving this but does not work.

Code Block
struct ContentView: View {
  @State private var name = ""
  
  var body: some View {
    VStack {
      Text("Hallo \(name)")
      TextField("Please enter your name", text: $name)
    }
    .onCopyCommand(perform: {
      print("You got to onCopy")
      var items = [NSItemProvider]()
      let stringData = "Hallo \(name)".data(using: .utf8)!
      items.append(NSItemProvider(item: stringData as NSData, typeIdentifier: kUTTypePlainText as String))
      return items
    })
  }
}


When the user selects something in the TextField, then using the copy menu should copy that text to the clipboard but when it has nothing selected, then I want to copy "Hallo" and the name to the clipboard.

As you can see, I tried using the onCopyCommand but Copy is always grayed out.

Any ideas on how I can enable Copy on the menu, and handle it when the TextField does not have anything selected?
Answered by oreman in 662118022
I've raised a TSI for this and the conclusion was that it is not possible. NSTextView and NSTextField would have to be changed to allow this. The issue is that they do not pass the copy: selector up the responder chain when it is not handled so it stops there.
Accepted Answer
I've raised a TSI for this and the conclusion was that it is not possible. NSTextView and NSTextField would have to be changed to allow this. The issue is that they do not pass the copy: selector up the responder chain when it is not handled so it stops there.
How do I implement a _global_ copy command for my app?
 
 
Q