Reputation:
I am writing a simple Python script with no GUI. I want to be able to drag and drop multiple files onto my python script and have access to their absolute paths inside of the script. How do I do this in Mac, Linux, and windows? For times sake, just Mac will be fine for now.
I've googled this question and only found one related one but it was too confusing. I am currently running Mac OS X Snow Leopard.
Any help is much appreciated.
Thanks!
Upvotes: 4
Views: 4381
Reputation: 85045
For OS X, the most straightforward way is to have your script run as part of an application bundle (.app
). You can use something like py2app to build a python application. Another approach might be to use Automator
or AppleScript
to create an app that takes the input parameters and passes them to the python script. An example of Automator usage is here.
Upvotes: 3
Reputation:
This really is independent of python. It depends entirely on which file browser you're using and how it supports drag and drop.
Upvotes: 1
Reputation: 175375
Usually when you drag a file onto a script/executable, the OS passes the path to that file as a command-line argument. Check sys.argv
Upvotes: 1