How to access clipboard data programmatically?

后端 未结 1 614
野性不改
野性不改 2020-12-29 12:03

How is it possible to access clipboard data on the Mac programmatically?

相关标签:
1条回答
  • 2020-12-29 12:57

    Apple has a Pasteboard Programming Guide the main class you are looking for is NSPasteboard

    The example for reading strings is

    NSPasteboard *pasteboard = <#Get a pasteboard#>; 
    NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil];
    NSDictionary *options = [NSDictionary dictionary];
    NSArray *copiedItems = [pasteboard readObjectsForClasses:classes options:options];
    if (copiedItems != nil) {
        // Do something with the contents...
    
    0 讨论(0)
提交回复
热议问题