To execute your Python script using KeyPirinha without encountering PowerShell execution policies or a visible console window, follow these steps:
Step 1: Correct the Command Path
Fix the typo in your command:
python C:\mydir\venv\Scripts\python.exe C:\mydir\main.py
However, this is redundant because python.exe is already the Python interpreter. You likely meant to use the virtual environment's Python to run the script. The correct command should be:
"C:\mydir\venv\Scripts\python.exe" "C:\mydir\main.py"
Step 2: Create a VBScript to Run the Script Hidden
VBScript can execute commands silently (without a console window). Create a .vbs file (e.g., run_script.vbs) with the following content:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\mydir\venv\Scripts\python.exe" & Chr(34) & " " & Chr(34) & "C:\mydir\main.py" & Chr(34), 0
Set WshShell = Nothing
- The
0 in WshShell.Run(..., 0) ensures the script runs hidden.
- Replace paths as needed.
Step 3: Configure KeyPirinha to Run the VBScript
- Install the "Run Command" plugin in KeyPirinha if you haven't already:
- Open KeyPirinha → Go to Settings → Plugins → Search for "runcommand" → Enable it.
- Add a custom command:
- Open KeyPirinha → Type
runcommand → Select "Configure Run Command".
- Add a new entry:
- Name:
Run My Script
- Command:
wscript.exe
- Arguments:
"C:\path\to\run_script.vbs"
- Assign a Hotkey (Optional):
- In the Hotkeys section, bind the command to a keyboard shortcut (e.g.,
Ctrl+Shift+M).
Alternative: Use pythonw.exe (for GUI Apps Only)
If your script is a GUI application (e.g., using Tkinter), replace python.exe with pythonw.exe (built-in Python GUI runner):
"C:\mydir\venv\Scripts\pythonw.exe" "C:\mydir\main.py"
- Configure KeyPirinha to run this directly (no VBScript needed).
Why This Works
- VBScript: Hides the console window entirely while running the script.
- pythonw.exe: Designed for GUI apps, suppresses the console by default.
Troubleshooting
This setup allows you to trigger your script silently via KeyPirinha without dealing with execution policies or visible windows.