PythonIDEを右クリックメニューから表示する
目的
Windowsで .py ファイルを右クリックしたときに「Edit with IDLE(Pythonの標準IDE)」をメニューに出したい。
でも環境によってはこれが表示されなかったり、別のエディタに関連付けを変えたときに消えたりする。
そこで、レジストリに直接「右クリックメニューを追加する設定」を書き込んで、PowerShellだけで復活させる。
# === 自分の環境の pythonw.exe に書き換える ===
$pythonw = "C:\Users\kenny\AppData\Local\Programs\Python\Python313\pythonw.exe"
# HKCR: をPowerShellで触れるようにする
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -ErrorAction SilentlyContinue | Out-Null
# .py に対応するクラス Python.File にメニューを追加
$menuKey = "HKCR:\Python.File\shell\Edit with IDLE"
if (-not (Test-Path $menuKey)) {
New-Item $menuKey -Force | Out-Null
}
Set-ItemProperty -Path $menuKey -Name "(default)" -Value "Edit with IDLE"
# 実際に起動するコマンドを登録
$cmdKey = Join-Path $menuKey "command"
if (-not (Test-Path $cmdKey)) {
New-Item $cmdKey -Force | Out-Null
}
Set-ItemProperty -Path $cmdKey -Name "(default)" -Value "`"$pythonw`" -m idlelib `"%1`""
# Explorerを再起動して反映
Stop-Process -Name explorer -Force
