The last thing I've been trying is to pass TC variables (such as %N, %P, %P%N, %S, etc) to a PowerShell .ps1 script as input parameters and then use them there again as variables now the PowerShell script's ones.
Here's the solution I've found so far [based on the $args array]:
PowerShell_test_TC_param_N_P_PN_PS_etc.ps1:
Code: Select all
$param = $args[0];"%N: $param"
$param = $args[1];"%P: $param"
$param = $args[2];"%P%N: $param"
$param = $args[3];"%S: $param"
$param = $args[4];"%P%S: $param"
$param = $args[5];"[%P]%S#1: $param"
$param = $args[6];"[%P]%S#2: $param"
$param = $args[7];"[%P]%S#3: $param"
$param = $args[8];"[%P]%S#4: $param"
$param = $args[9];"[%P]%S#5: $param"
""
'the $args array at the whole:'
$args
pause
Code: Select all
[em_tcps_test]
cmd=Powershell -ExecutionPolicy Bypass %commander_path%\PowerShell_test_TC_param_N_P_PN_PS_etc.ps1
param=""""%N""" """%P""" """%P%N""" """%S""" """%P%S""""
Code: Select all
TOTALCMD#BAR#DATA
em_tcps_test
wcmicons.dll
PowerShell_test_TC_params
0
10028
The %S-based group entries (with the list-like content depending on what was selected), if any, and if needed, can be caught individually by correspondent numbers of further $args[*] (here $args[3], $args[4], etc), and/or by other means for processing the PowerShell arrays.
Then the variables can be processed within a .ps1 script as needed.
Here's the example command output upon running where the file under the cursor is the script itself and some other random folder nearby has been selected:
Code: Select all
%N: PowerShell_test_TC_param_N_P_PN_PS_etc.ps1
%P: e:\TEST\Apps\TC\
%P%N: e:\TEST\Apps\TC\PowerShell_test_TC_param_N_P_PN_PS_etc.ps1
%S: various_tests
%P%S : e:\TEST\Apps\TC\various_tests
[%P]%S#1:
[%P]%S#2:
[%P]%S#3:
[%P]%S#4:
[%P]%S#5:
the $args array at the whole:
PowerShell_test_TC_param_N_P_PN_PS_etc.ps1
e:\TEST\Apps\TC\
e:\TEST\Apps\TC\PowerShell_test_TC_param_N_P_PN_PS_etc.ps1
various_tests
e:\TEST\Apps\TC\various_tests
Edit:
Initial [param=%N %P %P%N %S %P%S] string has been rewritten as [param=""""%N""" """%P""" """%P%N""" """%S""" """%P%S""""] to cope both the need of "quotation marks" for the names with spaces as long as the Total Commander and PowerShell parsing approaches.
Big thanks to u/Fla$her for the important remark.
NB
Explanation of the example PowerShell script:
The example script is harmless by design and does nothing more than just taking the current %N, %P, %P%N, %P%S, %S variables and displaying their current values (if any).
%N, %P, %P%N variables are predictable since always describe the file under the cursor in the active pane (its name, path, and both path/name), so the first three lines ($args[0..2]) of the script are enough to show that.
%P%S, %S variables are unpredictable as their values depend on what is selected in the active pane ($args[3..9] may show something or may show nothing)
In the end, for testing purposes, the script shows the $args array in full whether or not it's been embraced by the $args[0..9].
Note: As I now can see after all, as soon as the variables have been put in quotes, $args[5..9] become completely useless and normally won't ever return anything, so those strings could be omitted [on the contrary, if $args[5..9] are not empty, something goes wrong: see the screenshots below].