Promised Files or getting files from Apple's Photos app

To accept images dragged from Apple’s Photos, you must handle Promised Files. The Language Reference talks about dealing with Promised Files, but it’s out of date.

So I followed Apple’s documentation and made a module containing some DragItem extensions.
http://www.ohanaware.com/xojo/promisedFilesRedux.zip

You can use it like below:

Sub Open() me.acceptPromisedFiles End Sub

[code]Sub DropObject(obj As DragItem, action As Integer)
me.deleteAllRows
me.addrow “Promised file drop”

if obj.promisedFilesAvailable then
me.addrow "Format: " + obj.promisedFilesType

Dim destination as folderitem = specialFolder.desktop.child( "Dragged Files" )
destination.createAsFolder

Dim files() as folderitem = obj.promisedFilesAtDestination( destination )

For each file as folderitem in files
  me.addrow file.nativePath
  me.rowTag( me.lastindex ) = file
  
next

else
me.addrow “No promised files.”

end if
End Sub
[/code]

Note:
You must specify where you want the promised files to be created, as the promised files are created there. In terms of Apple’s Photos, you no longer have access to the original photo and cannot update it, so you must clean up these files when you’re finished with them.

Full source code included - so knock yourself out!

If you modify this code and re-distribute it, please provide original credit.

[quote=181216:@Sam Rowlands]To accept images dragged from Apple’s Photos, you must handle Promised Files. The Language Reference talks about dealing with Promised Files, but it’s out of date.

So I followed Apple’s documentation and made a module containing some DragItem extensions.
http://www.ohanaware.com/xojo/promisedFilesRedux.zip

You can use it like below:

Sub Open() me.acceptPromisedFiles End Sub

[code]Sub DropObject(obj As DragItem, action As Integer)
me.deleteAllRows
me.addrow “Promised file drop”

if obj.promisedFilesAvailable then
me.addrow "Format: " + obj.promisedFilesType

Dim destination as folderitem = specialFolder.desktop.child( "Dragged Files" )
destination.createAsFolder

Dim files() as folderitem = obj.promisedFilesAtDestination( destination )

For each file as folderitem in files
  me.addrow file.nativePath
  me.rowTag( me.lastindex ) = file
  
next

else
me.addrow “No promised files.”

end if
End Sub
[/code]

Note:
You must specify where you want the promised files to be created, as the promised files are created there. In terms of Apple’s Photos, you no longer have access to the original photo and cannot update it, so you must clean up these files when you’re finished with them.

Full source code included - so knock yourself out!

If you modify this code and re-distribute it, please provide original credit.[/quote]

Thomas Eckert ran into the same kind of need a few weeks ago https://forum.xojo.com/20807-accept-drop-thunderbird-attachment ; I am sure he would have loved this.

Thank you :slight_smile:

Would that also work for Mail? Will check…

Cool. Seems to work. Thanks!

Thank you very much for this work. It works perfect with Apple Mail. Now I can drop one email (multiple mails doesn’t work) from mail into my application, but this works only if I drop a single email from a non “organized” email. If you have activated “View => Organize by Conversation” in Apple Mail and you expand the mails and then you drop one of these mails into the application, the drag and drop doesn’t work.

Sam, thank you - I’m playing around with this technique and finding that if you drag from Photos.app, although the FolderItems are valid right away (as in, they are not nil), the actual files on disk take a while to get there - you can watch Photos.app first creates FileName.jpg.exporting before converting it to FileName.jpg.

This is a problem if you app expects the files to be there right away.

Any ideas how to handle this? Is there any sort of notification procedure for Photos.app to say “Yes, the file is actually there now”?

Here’s a link to a technique that uses FileSystemEventCenter to watch for the files appearing:
http://stackoverflow.com/questions/30110525/how-can-my-os-x-app-accept-drag-and-drop-of-picture-files-from-photos-app

For the app that uses this, I cheated and used a timer.

Hi
I am using the above techniques to handle emails dragged in from apple Mail:

  1. Sam’s Promised Files technique to accept dropped emails.
  2. FSEventsMBS to track the addition of the email to the defined folder (as sometimes this seems to be a long delay)
  3. MimeEmailMBS to generate an email class.

Now I want to delete the .eml file from the folder defined in PromisedFiles but I get an error 104 =File In Use. But in use by what, and how do I stop it being in use?

Promised files suck big time - I really hate that Apple has gone this method for Photos, so much wasted time and effort.

As usual with developing applications for Macintosh.

The alternative to promised files would be to store the data into the pasteboard, which is limited to 32 bit sizes, if not even less, however.

Also, I got the impression that the newer Cocoa APIs do not provide a way to generate the data only on request (when not using promised files) as it was with the older APIs. Or is that still possible, does someone know?

iPhoto and Aperture used to use a NSURL, which worked with everything… Very few apps are compatible with Photos, even handling file promises is not a good way as you end up with multiple copies of images.

Apple’s solution is to build a new ‘Photos extension’; which we cannot within Xojo.

[quote=238714:@Thomas Tempelmann]The alternative to promised files would be to store the data into the pasteboard, which is limited to 32 bit sizes, if not even less, however.

Also, I got the impression that the newer Cocoa APIs do not provide a way to generate the data only on request (when not using promised files) as it was with the older APIs. Or is that still possible, does someone know?[/quote]

The newer NSPasteboardWriting protocol makes promises fairly easy to do, for any data type. I don’t recall how it was done prior to 10.6, just that file promises were definitely doable.

Cool, let’s have a built in system for it then :slight_smile: