Drag and drop files onto my app

I need to create a simple app that will allow me to drag .wav files onto my app’s icon so I can batch process them. I’m on a Mac.

Any ideas how to get started here?

  • Console app or GUI app?
  • How to get my app to allow files to be dropped onto it?
  • How to get the list of files that were dropped onto it?

Did you check out the “FileDragAndDropTarget” class?
Not sure if it works with an App-Icon (i.e. minimzed application).
But I implemented this some time ago for a component inside my GUI.
I dont remember the details, but I think it was not too difficult to implement.

The application has to be running in order for that to work, though. If the application is not yet running and needs to be started when dragging files on the application icon, the dragged in files will be in the command line arguments. (Available when the JUCEApplication::initialise method is called.)

1 Like

I found this older topic on the issue although there’s not much information:

Sounds like the application’s .plist needs to permit drag-and-drop onto the application icon, which seems to be:

After that it should call JUCEApplication::anotherInstanceStarted(), but only once the app is running it seems? (reading juce_mac_MessageManager.mm line 173)

Here are my findings for OSX (tested with version 10.15):

  1. In the Projucer go to Exporters > XCode. Look for the field “Document File Extensions” and enter your file extension there.
  2. Now every time you drop a file with that file extension on your application icon, the function JUCEApplication::anotherInstanceStarted() is going to be called. No matter if your application was previously running or not. The file name will be part of the String argument, which anotherInstanceStarted() gives you.