Thdub/SingleInstanceAccumulator

Useful for multi-file shell context menu actions

★ 0Forks 0C#GitHub ↗Compare

README

SingleInstanceAccumulator

See typical stack-o's expressing the need, e.g. this one.

Explorer Context Menu config

::creates the entry
:: and crucial multi-file handling property
reg add "HKEY_CLASSES_ROOT\FileType\shell\YourNewContextMenu" /f /v "MultiSelectModel" /d "Player"

::your desired command line
reg add "HKEY_CLASSES_ROOT\FileType\shell\YourNewContextMenu\command" /f /ve /t REG_EXPAND_SZ /d "***see command line examples***"

e.g. On my system, for ".mov" files, I would replace FileType above with VLC.mov

Complex REG ADD example

Replace "*** see command line examples ***" above with your desired command line.

Note: quotes & environment variables must be escaped and escaping work slightly differently for the initial command versus later in the string!?!

Note2: this form works directly from interactive cmd.exe; if you're running from a batch file, all the %'s need to be doubled up (as is typical)

Note3: i've subsequently changed this context menu to associate to all file types (via "HKEY_CLASSES_ROOT*"), to avoid mapping to each file type individually.

λ reg add "HKEY_CLASSES_ROOT\*\shell\Transcode\command" /f /ve /t REG_EXPAND_SZ /d "\"^%bin^%\SingleInstanceAccumulator\" -f \"-c:powershell -ExecutionPolicy bypass "\"^%bin^%\transcode.ps1\"" -list '$files'\" \"%1\""

Usage

"-c:command line" (default: cmd /c echo $files && pause)
  $files will be replace with aggregated list

-f = output each item on separate line to new tempfile
  $files will be replaced by the tempfile path
  quote will default to nothing

-d:delimiter (default: ,)
-q:quote (default: ")
-t:timeout millisecs (default: 200)
-w = hidden launch
-v = debug output

Command Line Examples

note: initial command must have path for shell > command to work

put selected files onto clipboard

  • this is a fun use of delimiter to create multiple echo statements that are then piped to "clip" device
  • to script this in a registry "setup" batch file, we need to double escape the "&" and "|" characters...
    • once to avoid the initial setup batch file from interpreting them directly
    • and secondly to avoid the command line launched from SingleInstanceAccumulator from processing them
    • so that they are finally present to be run directly from the final cmd.exe

setup.cmd

reg add "HKEY_CURRENT_USER\Software\Classes\*\shell\Path2Clip\command" /f /ve /t REG_EXPAND_SZ /d "\"^%%bin^%%\SingleInstanceAccumulator\" -w -d:\" ^^^& echo \" \"-c:cmd /c (echo $files) ^^^| clip\" \"%%1\""

PowerShell & temp file

note: -f usage

%bin%\SingleInstanceAccumulator -f "-c:powershell -ExecutionPolicy bypass %bin%\test.ps1 -list '$files'" "%1"

PowerShell & inline files list

note: -q usage

%bin%\SingleInstanceAccumulator -q:' "-c:powershell -ExecutionPolicy bypass %bin%\test.ps1 -list $files" "%1"

test.ps1 (with temp file)

param(
  [String]$listFilePath
)

gc $listFilePath | % { $_ }

pause

erase $listFilePath

pause

test.ps1 (with files array parm)

param(
  [String[]]$filesList
)

$filesList | % { $_ }

pause

Contributors

Beej126

Issues