简体   繁体   中英

Run a script on a selected file from the context menu

I want to right-click any .mp3 file in the explorer and run my script from the context menu, which will load the path and name of this file into the script and play it. Can someone explain it with an example? Here is my script:

import playsound

bbb = 'camera.mp3'
playsound.playsound(bbb)
input()

Problem solved

we run regedit and look for: HKEY_CLASSES_ROOT \\ SystemFileAssociations \\ .mp3 \\ shell click right mouse on the shell and select a new key. we name it what we want it to appear in contextmenu. in my case, PlayAudio. HKEY_CLASSES_ROOT \\ SystemFileAssociations \\ .mp3 \\ shell \\ PlayAudio on PlayAudio, click right mouse and create a new key. we call it command. HKEY_CLASSES_ROOT \\ SystemFileAssociations \\ .mp3 \\ shell \\ PlayAudio \\ command we edit the command: C: \\ Python39 \\ python.exe C: \\ Python39 \\ Scripts \\ playsound \\ play.py% 1

Here is a simple script to play mp3 from menucontext:

import sys
import playsound
def play (file):
print ("Now playing:" + file)
playsound.playsound (file)
input ("press any key")

if __name __ == "__main__":
play (sys.argv [1])

Hope someone will benefit from it :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM