简体   繁体   English

从上下文菜单中对选定的文件运行脚本

[英]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.我想右键单击资源管理器中的任何 .mp3 文件并从上下文菜单中运行我的脚本,这会将该文件的路径和名称加载到脚本中并播放。 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.我们运行 regedit 并查找: HKEY_CLASSES_ROOT \\ SystemFileAssociations \\ .mp3 \\ shell 在 shell 上单击鼠标右键并选择一个新键。 we name it what we want it to appear in contextmenu.我们将它命名为我们希望它出现在上下文菜单中的名称。 in my case, PlayAudio.就我而言,PlayAudio。 HKEY_CLASSES_ROOT \\ SystemFileAssociations \\ .mp3 \\ shell \\ PlayAudio on PlayAudio, click right mouse and create a new key. HKEY_CLASSES_ROOT \\ SystemFileAssociations \\ .mp3 \\ shell \\ PlayAudio 在 PlayAudio 上,单击鼠标右键并创建一个新键。 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 HKEY_CLASSES_ROOT\\SystemFileAssociations\\.mp3\\shell\\PlayAudio\\command 我们编辑命令:C:\\Python39\\python.exe C:\\Python39\\Scripts\\playsound\\play.py%1

Here is a simple script to play mp3 from menucontext:这是一个从菜单上下文播放 mp3 的简单脚本:

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 :)希望有人能从中受益:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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