NSPasteboard is the Cocoa class representation for clipboard data, allowing information to be copied and pasted within and between programs. NSPasteboards also represent information that is being dragged within or among programs.
Questions tagged [nspasteboard]
161 questions
5
votes
2 answers
Get UTI of NSPasteboardTypeFileURL
NSFilenamesPboardType got deprecated on 10.14 and the suggestion is to use NSPasteboardTypeFileURL. This gives me filename as
file:///.file/id=6571367.12885025918
and NSWorkspace is unable to get UTI out of it.
How to get UTI from…

Marek H
- 5,173
- 3
- 31
- 42
5
votes
2 answers
How to paste an NSImage correctly from NSPasteboard?
Ok, Here's the code I'm using :
if let image = NSImage(pasteboard: pasteboard){
//..
}
And I have 3 ways where images come into the app:
If the image is dragged to the window, and using the dragging pasteboard, the image is correct.
If the…

pow-il
- 73
- 5
5
votes
2 answers
How to create NSPasteboardWriting for Drag and Drop in NSCollectionView
I have a one-section collection view and would like to implement Drag and Drop to allow reordering of the items. The CollectionViewItem has several textviews showing properties form my Parameter objects. Reading the doc I need to implement the…

JFS
- 2,992
- 3
- 37
- 48
5
votes
1 answer
Avoid blocking the main thread in a NSDraggingSession using a NSPasteboardItemDataProvider
In a Mac OS X app (Cocoa), I'm copying some images from my app to others using a NSDraggingSession. The NSDraggingItem makes use of an object that implements the protocol NSPasteboardItemDataProvider, to provide the data when the user drops it.
As…

Daniel
- 683
- 1
- 9
- 20
5
votes
1 answer
Error handling when keeping kPasteboardTypeFileURLPromise
My Mac app should allow dragging and dropping of kPasteboardTypeFileURLPromise to get file promises from or to the pasteboard.
As far as I understand, each NSPasteboardItem should have kPasteboardTypeFileURLPromise in its available types.
Unlike…

Yoav
- 5,962
- 5
- 39
- 61
4
votes
0 answers
Get HTML of selected link in a Mac OS X Service
I'm writing a Service that will be bundled with my application. The user should be able to right-click on a link in Safari (or another web browser) and call my Service and have it process the link (not just the text that gets selected when the user…

scottjacksonx
- 53
- 1
- 8
4
votes
1 answer
Write data to NSPasteboard and paste into Excel split by column and line
Regarding use of NSPasteboard by Swift. I want to write an OS X program to copy NSTableView data and paste it into Excel split by row and column, to match Excel format. Current code:
@IBAction func copyDataButton(sender: AnyObject) {
let…

Kevin Chang
- 191
- 1
- 7
4
votes
0 answers
Avoid large images with NSPasteboard
I'm working on an application that utilizes NSPasteboard as the medium to allow users to grab image files from other applications.
Occasionally a user will want to copy a very large image, which can lead to stalling the main thread pretty badly, as…

joshd
- 1,626
- 14
- 17
4
votes
2 answers
How to paste programmatically on OS X?
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…

Binarian
- 12,296
- 8
- 53
- 84
4
votes
1 answer
kPasteboardTypeFileURLPromise source example
Which application of Apple does support dragging of kPasteboardTypeFileURLPromise items?
I am implementation a kPasteboardTypeFileURLPromise dragging destination and I would like to test it against a dragging source that can be trusted.
(Finder is…

Yoav
- 5,962
- 5
- 39
- 61
4
votes
2 answers
Reading Multiple Dragged-n-Dropped Files
I have a small window inside the main xib (MainMenu.xib) with an NSImageView control for an OS X application. This view control has an NSImageView subclass that is supposed to accept files that the user brings (drag n drop). Since I have no…

El Tomato
- 6,479
- 6
- 46
- 75
4
votes
2 answers
NSPasteboard generalPasteboard returns nil
I'm attempting to copy an NSString to the pasteboard from within an NSBundle that is loaded inside another program as a plugin.
For some reason, [NSPasteboard generalPasteboard] is returning nil.
My code is from Apple's NSPasteboard documentation…

Michael Robinson
- 29,278
- 12
- 104
- 130
3
votes
1 answer
Attributed string loses attachment in pasteboard paste
I've spent quite a few days searching for a solution to putting an attributed string with attachment onto an NSPasteboard.
I can read an RTFD file with attachments, modify its text and attributes and then stick it on an NSPasteboard for use in…

dale
- 101
- 4
3
votes
0 answers
Swift - MacOS NSPasteboard - simultaneously support HTML and plain strings
I have a use-case where I want my application to store clipboard data and later allow the user to paste it out.
The thing is - I want to both support HTML-styled text (while maintaining its styling) and also support simple plain-text.
What I have…

Uri Yakir
- 141
- 10
3
votes
0 answers
NSPasteboard: Getting the name of the application that initiated a drag and drop session
My Cocoa app can receive Drag operations from other applications.
Is there a way to determine which other application initiated the drag (i.e. from where the data is coming from)?
I've implemented - (BOOL)performDragOperation:(id…

Mark
- 1,447
- 2
- 14
- 26