FAQs: How to create an button

English support forum

Moderators: white, sheep, Hacker, Stefan2

Post Reply
User avatar
Power Member
Power Member
Posts: 3235
Joined: 2007-09-13, 22:20 UTC
Location: Europa

FAQs: How to create an button

Post by *Stefan2 »

How to create an button

Right click on the button bar at the top and select "Change..."
(or utilize “Configuration > Button bar…”)

In the "Change button bar" dialog, click "Add", then fill in the properties as follows:

Code: Select all

Start path: 
Tooltip: your text
Enable "[_]Run minimized" or "[_]Run maximized", if wanted.
Press F1 key while in dialog for more.
Then click OK to create the button.
Picture: https://image.ibb.co/e9H36J/Buttonbar_Change_Eng.png

- If you see no button bar, utilize menu "Configuration > Options..." and enable "Layout" > [X] Show button bar.

- While the button is open for modification, press F1-key for more help.

- You do not need to fill out all of the fields.
-- "Command" is mandatory, "Icon" too, else the button is not visible.
-- "Parameters" and "Start path" only if need.

- Always quote ("...") your paths and parameters, just in case your (path/file name/user name) contain spaces.
-- But then, some parameters are automaticaly quoted by TC if TC find space.
-- You have to try and test if you need to quote and or not to quote.
-- Also, different Interpreters / Applications / Coding languages have different rules if and how to quote.

More Information:

Code: Select all

Command    = 
<Your script or application with full or relative path (use %Commander_Path%). 
Or a TC internal CM_commands or user defined EM_commands "UDC" (see "Magnifying glass" symbol)>

Parameters = 
<Parameters for your application, if need. Or TCs parameter for your script (press F1 key for help)>

Start path = 
<If need. Or leave empty (recommended), as TC use current path as "Start path".>

Icon file  = 
For more Icon resources / libraries visit: https://ghisler.ch/board/viewtopic.php?f=3&t=43593&p=305387#p305387>

Tooltip    = 
<a hint for you, so you know what this button will do. Use pipe-symbol '|' to insert line breaks.>

Enable "[_]Run minimized" or "[_]Run maximized", if wanted.

Environment variables in double % signs (%ProgramFiles% %COMMANDER_PATH%) must be written in den COMMAND box! (for unsupported exception see below)
TC internal variables with single leading % sign (%P %N %F) must be written in the PARAMETERS box!

If you need environment variables in double % signs in both command AND parameters box, then write them both in the command box:
Command: "%COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe"
Parameters: "%COMMANDER_PATH%\TOOLs\AHK\Flying Menu.ahk"

Command: "%COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe" "%COMMANDER_PATH%\TOOLs\AHK\Flying Menu.ahk"
Start path:
Icon: %COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe
Tooltip: AHK\Flying Menu - Do something

You also may be creative with quoting signs and experiment some time to get it working. Examples:
Stefan2 wrote: 2020-04-17, 05:32 UTC Did not work:
Command: cmd /k "%PROGRAMFILES%\!Tools\WSCC\SysInternals Suite\sigcheck.exe"
Parameters: %P%N
Der Befehl "C:\Program" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

Try this working example:
Command: cmd /k
Parameters: ""%%PROGRAMFILES%%\!Tools\WSCC\SysInternals Suite\sigcheck.exe" %P%N"
That is: " " % %PROGRAMFILES% % \!Tools\WSCC\SysInternals Suite\sigcheck.exe " %P%N "

Another for me working example:
Command: cmd /k ""%PROGRAMfiles%""\!Tools\WSCC\SysInternals Suite\sigcheck.exe"
Parameters: %P%N
That is: cmd /k " " %PROGRAMfiles% " " \!Tools\WSCC\SysInternals Suite\sigcheck.exe "

Yes, you can put environment variables in double % signs into the PARAMETERS box, but you have to double the % signs like in a DOS-Batch file.
But TC will not expand that var, it's the work of the called program to do the right thing:
ghisler(Author) wrote: 2020-04-19, 08:14 UTC If you put environment variables in double % signs in the parameters field, they will NOT be resolved by Total Commander.
They will be passed with single % signs to the target application. It's then the duty of the target application to resolve them.

If you want to resolve environment variables in Total Commander, you need to put them in the "command" field.
This field also accepts command line paramters as long as you properly quote names containing spaces.
Perhaps it is better to call your own script from an button, where you have more control over the workflow.


Example try of doubled double percent signs:

Code: Select all

Command=cmd /c
Parameters=Start "" "%%Commander_Path%%\Tools\Notepad2.exe" %P%N
(Please note that TC will quote %P%N himself, so don't quote them by yourself)
(Please note that MS-DOS START command expect first "..." to hold wanted windows title, an empty title in our example)


Example of Execute command line tool with two selected files
Stefan2 wrote: 2017-05-05, 08:51 UTC Execute command line tool with two selected files
Post by *Stefan2 » Fri May 05, 2017 10:51

Just tested:
I think %C1 and %C2 are the right parameters

Command: cmd /k
Parameters: ECHO pdftk "%C1" multistamp "%C2" output stamped.pdf
Icon: C:\windows\system32\cmd.exe
Tooltip: Test pdftk with "%C1"

Result (same panel):

Code: Select all

pdftk "X:\PSPad5\Language\Bulgarian.ini" multistamp "X:\PSPad5\Language\Esperanto.ini" output stamped.pdf
or (from both panels)

Code: Select all

pdftk "X:\PSPad5\Language\Bulgarian.ini" multistamp "Z:\PDF\pdftk\pdftk.1.txt" output stamped.pdf

Post by *MVV » Fri May 05, 2017 12:25
%C1 and %C2 return first two files from combined selection in both panels, so it may be confusing when there are selected files in some panel.
It would be easier to use just %P%N for the focused file in active panel and %T%M for the focused file in inactive panel.

So I would use such button:
Command: cmd.exe
Parameters: /c "pdftk "%C1" multistamp "%C2" output "%P\stamped.pdf""

Finally, you don't need cmd.exe at all, you can start pdftk directly:
Command: pdftk
Parameters: "%C1" multistamp "%C2" output "%P\stamped.pdf"

This will use focused files in both panels and produce stamped.pdf file in active panel.

- - -

Visible Command options:
Command: '-1' insert an separator between two buttons (an free space, and with option '[x]Flat Icons' a pipe-like symbol '|')
Command: '-2' insert a line break in button bar to get two rows.

ghisler(Author) wrote:
The button bar auto-wraps when it becomes too wide
Total Commander 7.5 will support both a user-defined line break in the bar (command: -2)
and an unlimited number of lines!

Hi, my TC main button bar (the one at the top) is showing icons in just one line.
If the screen resolution is not enough to show all the icons, they just not show.
I remember a second line of icons on lower screen resolutions...
petermad wrote:
Set BarLimitLines=0 in the [Buttonbar] section of your wincmd.ini

- - -

Rearrangement button bar elements
StickyNomad wrote: 2006-01-05, 18:15 UTC by *StickyNomad » Thu Jan 05, 2006 19:15

You can use cut and paste to reorder your buttons:
- right click and cut any button,
- then right click another button and select 'paste'.
The button will be inserted near the destination button.

You can control whether the pasted button should be inserted left/right from the destination button
if you right click near the left/right margin of the destination button.
ghisler(Author) wrote: 2006-01-06, 17:33 UTC by *ghisler(Author) » Fri Jan 06, 2006 18:33
The button bar isn't currently arrangeable via drag&drop to avoid accidental unwanted changes to the button bar.
You can drag&drop buttons in menu "Configuration - button bar", though if you don't want to use copy+paste.

- - -

What to put as command and parameter into an Button?

Read the help of the application in question if and how it supports to run an special action as command line command.
Next try that command yourself inside of a black cmd.exe console window (Command Prompt ; command-line interpreter). (https://en.wikipedia.org/wiki/Cmd.exe)

Once you know how that work, create a Total Commander UserDefinedCommando with that found out command.
To that UDC you can assign in next step a keyboard shortcut.

FAQs: User-Defined Command (UDC) (usercmd.ini) em_command
- Create own commands to use in button or to execute them by an keyboard shortcut.
>> viewtopic.php?p=344777#p344777

Such an UDC you can also use as Command in an Button for the TC-Buttonbar.
Or use that command and parameter directly in an Button.
FAQs: How to create an button / Icons / Variables / Quoting >> viewtopic.php?p=344803#p344803

TC will support you by providing Parameters to pass current Files, FileS or FolderS, Target path and more to an external script or application.
Open the help, search for "Button" to find "Dialog box: Configuration - Change button bar"
(((Or click "Operations > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar.")))
There you can find parameters to pass to the other application, like
%P > the source path to be inserted into the command line, including a backslash (\) at the end.
%N > places the filename under the cursor into the command line.
%T > inserts the current target path.
%S > insert the names of all selected files into the command line.
%L, %F and more > create a list file with the names of the selected files and directories.

Such an "%F" list you can use for application supporting such lists, like for example 7z or rar:
rar <command> -<switch> <archive> <@LISTFILES...> <path_to_extract\>
or use an own create script (MS-DOS batch;VBS;PowerShell;AutoHotkey;...) to loop over such an list file.

Script examples (w/o your special issue)

Powershell -Example

Code: Select all

# // The script
# // Check arguments:
If ($Args.Count -eq 0) { "Please use '%L' as TCs parameter. Also select one or more files first. Script quits here."; return}
# //DEBUG:
# Notepad $Args[0]
# //Do the WORK:
 TYPE $Args[0] | ForEach{ ...}

Code: Select all

sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L"
  If  FSO.FileExists(sTCtempList) Then
      WSO.run "notepad " & sTCtempList
      Set oTextStream = FSO.OpenTextFile(sTCtempList,FORREADING)
      Do Until oTextStream.AtEndOfStream
      WScript.Echo "Input file  sTCtempList  not found."
   End If

Code: Select all

Loop, Read, %vTCtempfile%
    vCurrTempFileLine = %A_LoopReadLine%
    MsgBox Curr line is:`n%vCurrTempFileLine%

MS-DOS Batch Example

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem Button Command: cmd /k
rem Button Parameters: "%F" "%P" "%T"
set tc_lst=%1
set tc_src=%2
set tc_dst=%3

if -%3==- echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF

for /F "usebackq delims=" %%I in (%tc_lst%) do (
   rem ============== Insert your custom commands here ==============
   echo Exp:       %%~I
   echo Full Path:   %%~fI
   echo LW:      %%~dI
   echo Path:      %%~pI
   echo File Name:   %%~nI
   echo Extension:   %%~xI
   echo ShortPath:   %%~sI
   echo Attrb:      %%~aI
   echo Date Time:   %%~tI
   echo Size:      %%~zI
   echo ----------------------------
   rem ==============================================================


Code: Select all

Command    = cm_CopyNamesToClip
Parameters = 
Start path = 
Icon file  = WCMICONS.DLL
Tooltip    = Copy filenames to clipboard
See TOTALCMD.INC file for more commands.

Code: Select all

Command    = cmd /c
Parameters = FOR /F "tokens=*" %%a in ('type "%L"') DO call C:\temp\tc-test.cmd "%%a"
Start path = 
Icon file  = C:\Windows\system32\cmd.exe
Tooltip    = ForEachFile Do call tc-test.cmd

Code: Select all

Command    = "%Commander_Path%\TOOLs\IrfanView\i_view32.exe"
Parameters = "%P" /thumbs /ini="%Commander_Path%\TOOLs\IrfanView\INI-Thumbs500"
Start path = 
Icon file  = "%Commander_Path%\TOOLs\IrfanView\i_view32.exe"
Tooltip    = Launch i_view32 with "/THUMBs 500x500"

Code: Select all

Command    = "%Commander_Path%\Tests\xxx"
Parameters = "%WL"
Start path = 
Icon file  = WCMICONS.DLL
Tooltip    = Denotation|Description|Explanation

- - -

FAQs: TCs' internal commands - how-to find and use them

FAQs: How to create an button (((THIS post)))

FAQs: Button-code: How-to Copy Share Paste a button ('TOTALCMD#BAR#DATA')

FAQs: User-Defined Command (UDC) (usercmd.ini) em_command

- - -

First, start a new instance of the command interpreter, Cmd.exe.

Try the xcopy command there:
xCOPY "D:\rive\path to\source.txt" "D:\rive\targetFolder\"
xCOPY "source.txt" "newNonExistentSubFolder\"
xCOPY "source.txt" "newFileWithoutExtension"

- - -

/c Carries out the command specified by string and then stops (close the black window).
/k Carries out the command specified by string and continues (keep window open to see error or process messages).

xcopy "source.doc" "c:\targetFolder\" (targetFolder will be created, don't forget the trailing backslash)

copy "source.doc" "target.doc"
copy "source.doc" "c:\targetFolder" (targetFolder must exist)

My copy&paste template

you may want to create an button like
Command: "D:\rive\path to\application\app.exe"
Parameters: <press [Help] to read more about %P%N or %S or "%F" TC-internal parameters, or search the forum or ask here for help>
<you may also have to read the documentation of the application in question how and IF it supports command line options>
Start path: <empty>
Icon file: WCMICONS.DLL or "D:\rive\path to\application\app.exe"
Tooltip: your text | line break

Instead you can create an "User defined command" which in turn you can use
as "Command:" in an button like above and also be able to assign an keyboard shortcut to.

Read more about in our collections of Q&A:
Deutsche FAQs >>> FAQs: Übersicht - Tipps & Tricks Sammlung >>> viewtopic.php?f=2&t=52423
English FAQs >>>>> FAQs: Summary - Tips & Tricks collection >>>>> viewtopic.php?f=3&t=52425

Post Reply