Export using Drag & Drop to Finder?

I have this idea for my document-based app that I'm not sure is possible, so I'm hoping someone with experience can shed some light on this for me.


Imagine I've got an NSDocument but it's actually represented as a package, a folder on disk. Let's call this folder-based document a Project document. Inside the Project document's package folder I've got, for all intents and purposes, BLOBs. These BLOBs are represented in the app's GUI as dragable UI elements.


Is it possible to code my app so that, when a user drags and drops one of these UI elements representing a BLOB into the Finder, a new Project document is created and the BLOB is placed inside this newly created package? The BLOBs can't exist outside of a Project document package, so if I want to export a BLOB it needs to be wrapped inside a Project document.


The BLOBs aren't of a known standard type such as an image file format or video file format. They are of a custom format that's only meaningful within the context of my app.


Does anyone know if this is possible?

I haven't done this, but that should be possible.


Look here how to handle custom types, and adapt to your Project Document Type.


h ttps://www.raywenderlich.com/1016-drag-and-drop-tutorial-for-macos

This should be possible. You will most likely want to do this through the pasteboard by creating a custom pasteboard type. In one of my apps, I have a custom "Blob" that is a dictionary containing various objects. I have that "Blob" as a custom readable and writable pasteboard type that allows me to copy and paste it from from one document to another document, save it on a stack for later, etc.


Once you figure out how to get your Blob on the pasteboard when your app is not running, it should be downhill thereafter. Register a service?

You can put a file promise on the pasteboard. If/when it is accepted, your code will be called to create the file at a particular URL.


To create the file promise, instantiate and configure an NSFilePromiseProvider object. You'll need to specify a delegate object and implement the methods of NSFilePromiseProviderDelegate. Then, write the file promise to the pasteboard with the writeObjects method.


There's sample code here.

> Once you figure out how to get your Blob on the pasteboard when your app is not running, it should be downhill thereafter.


My app will always be running, as they'll be dragging a UI element to the Finder.

Thanks Ken, I'll give that a look.

Export using Drag & Drop to Finder?
 
 
Q