9

Is there any way to configure a recent OS X system so that python scripts automatically behave as drag and drop targets? If not, what is the most light-weight way (ideally scriptable) of configuring individual scripts for this behavior?

On Windows, I can simply drag and drop files onto a python script, and a python process will be launched with the full path names of the dropped arguments available in sys.argv. Amazingly, not only does this not happen on OS X, but there doesn't seem to be any way of configuring the system to do this automatically. All the solutions I've come across involve wrapping each of my scripts in an app.

Sure, this question has been asked and answered before. But not only is every single answer I could find limited to enabling drag and drop for one script at a time (by wrapping an app around them); it seems that all answers are obsolete and/or depend on broken links. Here's a sampler:

As mentioned, none of them seem to work anymore. I have OS X 10.8, Mountain Lion, and I've seen zilch that could be expected to work on later OS versions. Any up to date solutions?

PS: Conceptually this question is not necessarily limited to python: I'm pretty sure that any mechanism that would work with shell or perl scripts would also work with python. But given how hard this seems to be on OS X, I'm keeping the question specific since that's my use case, and all solutions I've seen seem to be language-specific.

Community
  • 1
  • 1
alexis
  • 48,685
  • 16
  • 101
  • 161

1 Answers1

5

Have you seen this answer? Try using Mac OS X Automator (available in current and past versions of the OS--just tested this in Yosemite). As far as "one at a time" vs "multiple", this SuperUser post about the same subject explains how to make it work for multiple files.

At the end of the day, "Drag and Drop Support" is functionality of the Windowing System and has nothing to do with Python. That said, you can build OS X GUI apps in Python, which could be another solution to this. Check out this link about GUI Applications in Python for more info.

Will
  • 24,082
  • 14
  • 97
  • 108
  • 1
    Thanks, I'll have to look at that again. Saw it a long time ago, don't remember what problem I ran into. But let's just say I agree that this **should be** a functionality of the windowing system... clearly the OS X setup leaves a lot to be desired, and there are python-specific paths to wrapping an app... – alexis May 03 '15 at 21:52
  • Yeah, report back if you get it to work, since others, myself included, could benefit from this ;) Automator sounds like the standard-MacOS way to do it, but you could definitely also build a simple OS X app in whatever language to do it. Apparently all you have to do for a native app is just [configure a few things in your app's plist](https://stackoverflow.com/questions/501079/how-do-i-make-an-os-x-application-react-when-a-file-picture-etc-is-dropped-on). – Will May 03 '15 at 22:58