Search code examples
objective-cmacoscocoaswiftnspasteboard

Globally replace NSPasteboard.generalPasteboard()


I want the NSPasteboard.generalPasteboard() to be temporarily switched to a custom one generated by my app using NSPasteboard.pasteboardWithUniqueName()

So that when the user presses Cmd+C/Cmd+V while the pasteboard is switched, my app's pasteboard gets used instead of the general pasteboard.

Is there a way to do this?


Solution

  • No, there's no way to do this.

    If you're only looking to change the behavior within your own app, you can add a category/extension to NSPasteboard to add a method that returns either the general pasteboard or your app's private pasteboard. That at least isolates the logic to one place. Everywhere else in your code, you'd use you custom method instead of +generalPasteboard.

    If you're looking to change the behavior of other apps, too, then you're out of luck. What is the higher-level goal you're trying to achieve? Why do you want to change which pasteboard apps use? If you explain that, perhaps there's another way to achieve that goal.