How to check if NSPasteboard is updated?

I can automate the copy command to place any text on the file cabinet every second or so - unfortunately, this is the only way to access text that is in another application. After copying, I get the text and process it.

Sometimes a copy command is sent when nothing is selected - for example, in textEdit, if the cursor is at the end of the line (instead of highlighting some text), and you press the copy, you get a system sound because nothing is selected for copying. Cardboard does not update and retains its previous data.

I cannot think of a creative way to determine when this will happen. If I send a copy command and the cardboard does not update, is there any timestamp on the file cabinet that I can access to confirm that something was or was not captured?

I looked at changeCount, but I'm not sure if this is accurate, and the documentation didnโ€™t really help me - red herring?

Any simple and effective ideas were gratefully received!

+4
source share
2 answers

I do not believe there is a notice for this, but you can interview a file cabinet.

pasteboard = [[NSPasteboard generalPasteboard] retain]; [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(pollPasteboard:) userInfo:nil repeats:YES]; - (void)pollPasteboard:(NSTimer *)timer { NSInteger currentChangeCount = [pasteboard changeCount]; if (currentChangeCount == previousChangeCount) return; NSLog(@"Pasteboard updated: %@", [pasteboard types]); previousChangeCount = currentChangeCount; } 
+11
source

Just copy the same jpeg file from your desktop several times and you will see that it doesnโ€™t work with

NSLog(@"Pasteboard updated: %@", [pasteboard types]); (

sometimes:

 2014-05-25 12:14:20.014 PB1[65771:303] ( "public.file-url", "CorePasteboardFlavorType 0x6675726C", "dyn.ah62d4rv4gu8y6y4grf0gn5xbrzw1gydcr7u1e3cytf2gn", NSFilenamesPboardType, "dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu", "Apple URL pasteboard type" ) 

sometimes:

 2014-05-25 12:14:25.482 PB1[65771:303] ( "public.file-url", "CorePasteboardFlavorType 0x6675726C", "dyn.ah62d4rv4gu8y6y4grf0gn5xbrzw1gydcr7u1e3cytf2gn", NSFilenamesPboardType, "dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu", "Apple URL pasteboard type", "com.apple.icns", "CorePasteboardFlavorType 0x69636E73", fccc, "public.utf16-external-plain-text", "CorePasteboardFlavorType 0x75743136", "public.utf8-plain-text", NSStringPboardType, "public.tiff", "NeXT TIFF v4.0 pasteboard type" ) 
0
source

Source: https://habr.com/ru/post/1310507/


All Articles