nspasteboard

Receive promised e-mail in macOS 10.12+

这一生的挚爱 提交于 2019-12-10 10:55:09
问题 Previously, I was using the following to discover e-mail meta-data from a drag & dropped e-mail(/-thread) from Mail.app. if let filenames = draggingInfo.namesOfPromisedFilesDropped(atDestination: URL(fileURLWithPath: destinationDir!)) { /// TODO: in future implementation Mail might return multiple filenames here. /// So we will keep this structure to iterate the filenames //var aPaths: [String] = [] //for _ in filenames { if let aPath = pb.string(forType: "com.apple.pasteboard.promised-file

Drag Files come across Sandbox(__CFPasteboardIssueSandboxExtensionForPath)

不想你离开。 提交于 2019-12-10 04:08:10
问题 I processed drag operation from browser view to custom view.It work well in snow lepoard,but not in Mountain Lion with sandbox. in browser view: NSMutableArray* urls = [[[NSMutableArray alloc] init] autorelease]; ..............put some NSUrl to urls array.................... [pasteboard writeObjects:[NSArray arrayWithArray:urls]]; in my receive custom view: NSArray* pasteboardItems = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSString class]] options:nil]; NSArray*

Reading from the clipboard with Swift 3 on macOS

 ̄綄美尐妖づ 提交于 2019-12-09 06:33:11
问题 I'm a beginner with Swift, and I'm trying to figure out how can I read what has been copied to the clipboard On macOS (Swift 3)? I've searched a lot but can't seem to find anything that works. A few of the things I've tried from online: var pasteboardItems: [NSPasteboardItem]? { get } print("\(pasteboardItems)") and let pb = NSPasteboard.general() pb.string(forType: NSPasteboardTypeString) print("\(pb)") and let pasteboard = UIPasteboard.general if let string = pasteboard.string { // text was

Does NSPasteboard retain owner objects?

不羁岁月 提交于 2019-12-08 07:10:48
问题 You can call NSPasteboard like this: [pboard declareTypes:types owner:self]; Which means that the pasteboard will later ask the owner to supply data for a type as needed. However, what I can't find from the docs (and maybe I've missed something bleeding obvious), is whether or not owner is retained. In practice what's worrying me is if the owner is a weak reference, it could be deallocated, causing a crash if the pasteboard then tries to request data from it. Note: I should probably clarify

How to paste programmatically on OS X?

穿精又带淫゛_ 提交于 2019-12-08 03:32:50
问题 I have access to the general NSPasteboard . I wrote to the pasteboard my NSData . NSPasteboard *pboard = [NSPasteboard generalPasteboard]; [pboard clearContents]; [pboard setData:newContent forType:type]; Now I want to paste programmatically . The text cursor is blinking on the correct position in another app . Hitting ⌘ + V works. Somebody know how? Maybe how to paste with calling the shortcut programmatically? 回答1: If you want to perform the paste action in your own app, then you can use

Receive promised e-mail in macOS 10.12+

青春壹個敷衍的年華 提交于 2019-12-06 07:36:37
Previously, I was using the following to discover e-mail meta-data from a drag & dropped e-mail(/-thread) from Mail.app. if let filenames = draggingInfo.namesOfPromisedFilesDropped(atDestination: URL(fileURLWithPath: destinationDir!)) { /// TODO: in future implementation Mail might return multiple filenames here. /// So we will keep this structure to iterate the filenames //var aPaths: [String] = [] //for _ in filenames { if let aPath = pb.string(forType: "com.apple.pasteboard.promised-file-url") { return aPath } //} //return aPaths } Kind of janky, but it worked, since "com.apple.pasteboard

How to save off the pasteboard contents first and restore them afterward?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 18:09:53
问题 I have a faceless Mac OS X app which needs to copy selection from other apps. I achieve this by simulating CMD+C keystrokes. It works perfectly. But there is a, I think it's critical, side effect. It'll override users' pasteboard without their permission. So I was thinking before I copying selection I should save pasteboard content and then restore it. Can someone give me some hint, maybe sample code? 回答1: Here's a category on NSPasteboard that I wrote to do this. It seems to work pretty well

Determine the source application of current pasteboard content

爷,独闯天下 提交于 2019-12-05 05:56:05
Several OSX clipboard managers from AppStore show the ability to determine the source-application of content that was copied to the clipboard. I am writing some simple clipboard observer and would like to show the source-application icon near the content, stored in general NSPasteboard. And I would like to know how this can be achieved. As far as I can see, NSPasteboard doesn't provide any additional info except types of data and data itself. Maybe there are some events or notifications to know that a 'copy' command was triggered? Or some other ways? I believe that the way CopyLess and Alfred

Drag Files come across Sandbox(__CFPasteboardIssueSandboxExtensionForPath)

。_饼干妹妹 提交于 2019-12-05 04:29:39
I processed drag operation from browser view to custom view.It work well in snow lepoard,but not in Mountain Lion with sandbox. in browser view: NSMutableArray* urls = [[[NSMutableArray alloc] init] autorelease]; ..............put some NSUrl to urls array.................... [pasteboard writeObjects:[NSArray arrayWithArray:urls]]; in my receive custom view: NSArray* pasteboardItems = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSString class]] options:nil]; NSArray* pasteboardItems2 = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:nil];

How do I handle multiple file drag/drop from Finder in Mac OS X 10.5?

…衆ロ難τιáo~ 提交于 2019-12-03 12:39:01
I need to get the URLs of all files dragged/dropped into my application from Finder. I have a Cocoa app running on 10.6 which does this by using the new 10.6 NSPasteboard APIs which handle multiple items on the pasteboard. I'm trying to backport this app to 10.5. How do I handle this on 10.5? If I do something like below, I only get the first URL: NSArray *pasteTypes = [NSArray arrayWithObjects: NSURLPboardType, nil]; NSString *bestType = [pboard availableTypeFromArray:pasteTypes]; if (bestType != nil) { NSURL *url = [NSURL URLFromPasteboard:pboard]; } The IKImageKit programming topics outline