Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding context menu option through Python

I'm trying to make a small Python script that is executed by clicking an option in a file's context menu. It would execute something like "path_to_script %L", where %L is (I think) the location of the file the user has right-clicked. I know I have to add something to the registry for that option to appear, but _winreg is getting confusing. What do I have to do to add a registry entry (through Python) so my script can be called like that?

like image 522
Dan Hlavenka Avatar asked May 06 '26 21:05

Dan Hlavenka


1 Answers

I dont know how you can remove from registry (probably manually or _winreg) but you can follow a way like that per your custom python script to registration to windows.

registerOne.reg

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\One]
[HKEY_CLASSES_ROOT\*\shell\One\command]
@="python.exe one.py \"%1\""

one.py

def registerScriptToContextMenu ():
    # http://support.microsoft.com/kb/310516
    cmdLine = 'regedit.exe registerOne.reg'
    import os
    os.system(cmdLine)

def one_main (*args):
    pass
like image 51
jack-london Avatar answered May 09 '26 11:05

jack-london



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!