View Single Post
Old 8th October 2019, 23:18   #8  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
Hello BetA13,

it does allow you to customize the context menu in Windows File Explorer. You can create your own menu items and define when they are shown, how they are shown and what they do when you click on them, the short answer is it runs a command line so basic command line knowledge is required.

StaxRip executes command line tools so working on that I learned the basics but really never embraced the command line concept, I never bothered to learn windows batch scripting and never will. Also for staxrip I needed a player with a decent command line interface and mpv was really the only player having that, so I started to learn mpv and this finally after 20 years opened my eyes on how powerful the command line is, so I started to embrace the concept and get serious on learning powershell.

When they are shown

It means you can define for which type of file or folder they are shown. You can define that the menu is shown for all file extensions or only for certain file extensions or for directories.

Example Visual Studio Code:

It's a really amazing text/code editor, there are too many file extensions for text files so it makes sense to show the menu item of Visual Studio Code for all files, even for mkv etc. To do this you enter *.* in the File Types field. Visual Studio Code allows you also to open a folder, it is useful for many types of projects and languages but also for any type of text file. It has a find in files feature that will search for a string in all files of the opened folder including all sub folders. There are tools like File Locator Pro that can do that too but why install an extra tool if you already have one that can already do the job. What will also work for this task is PowerShell:

PS1> Get-ChildItem -Recurse | Select-String regex

Trash\rename.ps1:1:$pattern = Read-Host -Prompt "Enter a regex pattern"


PS1> gci -rec | sls regex

Trash\rename.ps1:1:$pattern = Read-Host -Prompt "Enter a regex pattern"

To show a menu item for folders in Open with++ check 'Show for directories', the menu item will be shows if you right-click a folder or a folder background. My full definition for VS Code is:

Name: Visual Studio Code
File Types: *.*
Path: C:\Program Files\Microsoft VS Code\Code.exe
Arguments: %paths%
Show for directories: checked

How they are shown

This means simply either on top level or in a submenu which is called: Open with++

My most often used menu commands are:

Visual Studio Code
PowerShell
Copy Paths

Since I use these menu command very often I show them on top level instead of in the 'Open with++' submenu, other more rarely used menu command such as mkvtoolnix gui, mpc-be, mpc-hc, mpv, staxrip, virtualdub2, vlc etc. are in my 'Open with++' submenu because I use these commands not so often. What is on top level because I use it often is MediaInfo, for that I have my own frontend:

Name: MediaInfo
File Types: %audio% %video% %subtitle% %image% (that are macros defined in the options dialog, these macros are used for all menu commands that deal with audio, video, subtitle and image files)
Path: D:\Projekte\VB\StaxRip\bin\StaxRip.exe
Arguments: -mediainfo %paths%

I made some improvements to my MediaInfo frontend in recent staxrip beta builds.

Currently I'm working hard on improving my PowerShell knowledge so I have a PowerShell menu command on top level, to show it I right click a folder or folder background and select the command in the menu. Windows has that built in by pressing shift key. The definition for my powershell menu command is:

Name: PowerShell
Path: powershell
Arguments: -nologo
Show for directories: checked

That's all because 'Open with++' will set the working directory to the directory of the selected files or folders. If you want to use ancient legacy tech that never was any good then you can show the command prompt with:

Name: CMD
Path: cmd
Show in submenu: checked
Show for directories: checked

Windows Terminal Preview can be used like so:

Name: Windows Terminal
Path: wt
Show for directories: checked

Windows Terminal does unlike cmd and powershell not start with the proper working directory but it has a setting to make it work: "startingDirectory" : null

https://www.microsoft.com/en-us/p/wi...ot:overviewtab

Very often the file or folder paths have to be copied to the clipboard, this is especially true if you code, because of that Windows has that built pressing shift before you open the context menu, I don't want to use the shift key all the time so I have my own menu command:

Name: Copy Paths
File Types: *.*
Path: powershell
Arguments: -file "D:\Projekte\PS1\copy paths.ps1" %paths%
Show for directories: checked
Run hidden: checked

'Run hidden' prevents the terminal to be shown, for this task it's not that useful. The -File switch of powershell tells powershell to run a powershell script, when the -File switch is used powershell will exit afterwards, this can be prevented with -noexit switch or in code with things like Pause or Read-Host. The %paths% macros will expand to the selected files and folders, in powershell it can be accessed with the $args variable. The full code needed for the Copy Paths menu command is pretty simple:

Code:
Set-Clipboard ($args -join "`r`n")
What they do when you click on them

It runs a command line, for that you define a Path and Arguments. ShellExecuteEx is used to run it. The shell extension is done with C++ as dotnet is not suitable for it. The selected files and folders are available in the %paths% macro, it expands to "file1" "folder1" etc. It expands environment variables in the Path and in the Arguments. You can define 'Run as admin' or if you only sometimes need something running as admin you can press shift or control.

Last edited by stax76; 9th October 2019 at 00:55.
stax76 is offline   Reply With Quote