I am working in Mac OS X and have been writing simple file/folder copy scripts in Python. Is there a way to drag and drop a folder on top of a Python script icon and pass the fi
What you might really like is Mac OS Services. They are Automator workflows which can nicely integrate into the operating system in a context-specifc manner: e.g. you can make your script appear in Finder's context menu when you select a folder.
You can make a service from python script in following way:
Now you can either use default bash shell (/bin/bash
) to call your script:
/full/path/to/your/python /full/path/to/your/script.py $@
Or use /usr/bin/python
(default python) and paste your code directly into text block;
Pass input: as arguments
in top right corner of the block.It's a little bit tricky to debug such workflows (as you won't see stdout & stderr). Possible workaround for debugging is to setup custom excepthook
and output all exceptions into some plain text file:
import sys, traceback
def excepthook(type, exc, tb):
with open("error.log", "a") as f:
traceback.print_exc(file=f)
sys.excepthook = excepthook