Marc Adler - 1 year ago 80
Python Question

# Python script won't run from the context menu

[Submitted to superuser two days ago, but nobody could answer it, so reposting here.]

Working on the basis of this post (and this follow-up post), I've tried adding a python script (which I've added to the path and so on, so that I can run it from the command line everywhere in the system) to the context menu, like this:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\get_abs]
@="&Get Abstracts"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"

[HKEY_CLASSES_ROOT\Directory\Background\shell\get_abs\command]
@="C:\\cmdtools\\get_abs.py"


However, I get a strange error message when I try to run it.

To be clear, I have successfully run this script from the command line (using powershell, in case it matters) in the folder in which I'm trying to run it from the context menu.

Python scripts aren't natively executable by Windows; it's complaining that you didn't specify an .exe file. That's easy though, you just specify python.exe. Follow that up with the path to your script and then a %1 -- this is a placeholder for the path to the clicked file. To allow your command to work with paths with spaces in them, surround the %1 with quote marks. Putting it all together, we get:
C:\path\to\python.exe C:\path\to\your\script.py "%1"