utils icon indicating copy to clipboard operation
utils copied to clipboard

Don't assume Notepad is installed, instead get the default app for .txt files to edit the script.

Open Aetopia opened this issue 1 year ago • 4 comments

Changes

  • Instead of assuming Notepad is installed by default, grab the default app for .txt files to edit the script:
try { 
    [string] $Class = ((Get-Item "Registry::HKEY_CLASSES_ROOT\.txt\OpenWithProgids") | Select-Object -First 1).Property
    [string] $Path = "Registry::HKEY_CLASSES_ROOT\$Class\shell\open\command"
    [string] $Command = (Get-ItemPropertyValue -Path $Path -Name "(Default)")
    Invoke-Expression "& $($Command.Replace("%1", ($argv | Select-Object -First 1)))"
}
catch {}

Aetopia avatar May 07 '24 11:05 Aetopia

best would be to use https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/invoke-item?view=powershell-5.1

also try to do formatting in separate commits, or even better respect the coding style

couleurm avatar May 07 '24 12:05 couleurm

best would be to use https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/invoke-item?view=powershell-5.1

also try to do formatting in separate commits, or even better respect the coding style

Reverted any formatting changes, now the script just includes the required code.

Also Invoke-Item won't work, as the documentation says it executes the default action on a specified item. In the case of batch scripts, it will just start a new instance of it.

What we want to use are Object Verbs unfortunately the edit verb for batch files launches Notepad by default because of this its better to use the default application for .txt files.

Aetopia avatar May 09 '24 09:05 Aetopia

no catch?

couleurm avatar May 09 '24 11:05 couleurm

image on windows sandbox

couleurm avatar May 09 '24 11:05 couleurm