FAQs: How to create an button

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Stefan2
Power Member
Power Member
Posts: 4153
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

Command: 
Parameters:  
Start path: 
Icon file: WCMICONS.DLL
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



There is also a wiki entry >> https://www.ghisler.ch/wiki/index.php/Buttonbar



Note:
Note
- 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  = 
<e.g.: WCMICONS.DLL
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:
INSTEAD of
Command: "%COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe"
Parameters: "%COMMANDER_PATH%\TOOLs\AHK\Flying Menu.ahk"

USE
Command: "%COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe" "%COMMANDER_PATH%\TOOLs\AHK\Flying Menu.ahk"
Parameters:
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 "

HTH? :D
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.


Update 2023 für TC v11 >> %|Commander_Path| (see History.txt)
%Commander_Path% only works in Command field.
%|Commander_Path| only works in Parameters field
IF your Command is for example cmd.exe or another program
that can resolve envars (Environment Variables) ,
THEN you can try to use %%Commander_Path%% in the Parameters field.




- - -

Quoting in INI-files

ghisler(Author) wrote: 2024-03-29, 14:16 UTC Re: [11.03] Sudden "No more files..." error
Post by *ghisler(Author) » Fri Mar 29, 2024 15:16

When reading from ini files, Windows removes any surrounding double quotes, e.g.
Editor="%COMMANDER_PATH%\AkelPad.exe" "%1"
-> %COMMANDER_PATH%\AkelPad.exe" "%1

Editor=""%COMMANDER_PATH%\AkelPad.exe" "%1""
-> "%COMMANDER_PATH%\AkelPad.exe" "%1"
petermad wrote: 2024-03-29, 16:09 UTC
When reading from ini files, Windows removes any surrounding double quotes
And Windows only does this if there are no unquoted characters after the last quotation mark:

Editor="%COMMANDER_PATH%\AkelPad.exe" "%1"
-> %COMMANDER_PATH%\AkelPad.exe" "%1
but:
Editor="%COMMANDER_PATH%\AkelPad.exe" "%1" /p
-> "%COMMANDER_PATH%\AkelPad.exe" "%1" /p

Same if there is unquoted characters before the first quotation mark
Editor=%COMSPEC% /C echo "%COMMANDER_PATH%\AkelPad.exe" "%1"
-> "%COMMANDER_PATH%\AkelPad.exe" "%1"
but:
Editor="%COMMANDER_PATH%\AkelPad.exe "%1"
-> %COMMANDER_PATH%\AkelPad.exe "%1"

- - -

---

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
https://ghisler.ch/board/viewtopic.php?t=47807

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!

Command: 'CD' and the char X as Icon file will create an Button without an Icon and without any function (see below at "Button as Placeholder / big spacer")



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


- - -

Button as Placeholder / big spacer

This trick will create an Button without an Icon and without any function
e.g. as an Placeholder / big spacer to adjust the following buttons horizontally more to the rights


Command: CD
Parameters:
Start path:
Icon: X
Tooltip: Blindbutton , Tue nichts , nix , DoNothing



Copy&Paste Buttoncode:

Code: Select all

TOTALCMD#BAR#DATA
CD

x
Blindbutton , Tue nichts , nix , DoNothing


-1
or:

Code: Select all

TOTALCMD#BAR#DATA
cm_wait 0

NUL
NUL


-1


- - -

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.

- - -

Create new own button bars or drop-down sub-menu

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", to add a new button for not to change the last button.

- [Change>>] > [Add Subbar>>] > browse to TC-folder > select an already existent *.bar file, or type in a name for a new file.
- a new dialog will open and show the content of the chosen *.bar file
(on TC10 and with a new *.bar file, there is now already an button for to go back to the bar you have started from)
- Check "[x]Show as menu" to see that bar as drop-down menu.

- manipulate now that bar, ... as above, click "Add" to add a new button, click [Help] to read more.
Command: Notepad
Parameters: %P%N
Start path:
Icon file: Notepad or WCMICONS.DLL
Tooltip: your text - open notepad with file under cursor
[OK]
[OK]

Now you have a new button, pointing to another bar file.
Click on it.
You will switch to that new bar. There is already an icon to go back to the last bar you came from.
Use that icon for to go back.
Modify the new bar. (Right click on the button and select "Change...")
Check "[x]Show as menu"
[OK]
Try the button again. Now you got a drop-down sub-menu.



Google for "Nested Button Bar Creator 2.00" if you want to see a nifty tool for this very task.


R.I.P. , "alav ha-shalom" dear ts4242 (Taher Salem, † 2019)

http://utceditors.totalcmd.net/tc_tools/nested_button_bar_creator/overview.htm
https://www.ghisler.ch/wikide/index.php/Nested_Button_Bar_Creator

https://totalcmd.net/plugring/bar_creator.html
Nested Button Bar Creator 2.00
Author: Taher Salem

https://ghisler.ch/board/viewtopic.php?t=8829
(New tool) Nested bar creator
Post by *ts4242 » Sun Oct 23, 2005 7:16



- - -


More Infos:

ghisler(Author) wrote: 2009-06-19, 20:00 UTC by *ghisler(Author) » Fri Jun 19, 2009 22:00
Sorry, I don't understand the problem. OPENBAR isn't meant for the button bar
because the button bar already opens .bar files automatically without any extra command...
-
-
OK, let me repeat that OPENBAR will always set a new button bar,
it will not open a dropdown bar, with or without shift.
-
-
The reason why OPENBAR doesn't support Shift to open as dropdown list is
that OPENBAR can also be used in other places like hotkeys or the main menu,
where this option wouldn't make any sense.
Therefore you have to give the bar name without OPENBAR if you want to get the submenu.
ghisler(Author) wrote: 2012-03-18, 16:38 UTC by *ghisler(Author) » Sun Mar 18, 2012 17:38
Indeed OPENBAR isn't meant for button bars because it works without it!
But since I cannot prevent users from adding it, I will add some code to detect and remove it.
ghisler(Author) wrote: 2021-06-18, 15:23 UTC by *ghisler(Author) » Fri Jun 18, 2021 17:23

> [em_mybar]
> cmd=OPENBAR pathtomy.bar
> ;plus shortcut

It's not possible because Total Commander wouldn't know where to show that menu when it's not opened from a button.
ghisler(Author) wrote: 2021-12-03, 09:01 UTC Re: Button bar opens as text file
Post by *ghisler(Author) » Fri Dec 03, 2021 10:01

The behavior is different with OPENBAR when the linked .bar file is invalid,
e.g. because the [Buttonbar] section header is missing:
1. Without OPENBAR, TC will try to open the .bar file with the associated program
2. With OPENBAR, you will get an empty button bar


So my guess is that the linked .bar file is damaged somehow.

Please open it with F4, it should start like this:
[Buttonbar]
Buttoncount=<number of buttons>
button1=<dll or exe name>,<index>
cmd1=<a command>
iconic1=0
menu1=label
button2=<dll or exe name>,<index>
etc.


- - -



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.
>> https://ghisler.ch/board/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 >> https://ghisler.ch/board/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

 Cmd=Powershell 
 Param="%L"
# // 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{ ...}
VBS-Example

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
      ...
      Loop
      oTextStream.Close
   Else
      WScript.Echo "Input file  sTCtempList  not found."
   End If
AHK-Example

Code: Select all

vTCtempfile=%1%
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 ==============================================================
)
pause
cls
endlocal







Button-Examples:

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
https://ghisler.ch/board/viewtopic.php?p=289931#p289931

FAQs: How to create an button (((THIS post)))
https://ghisler.ch/board/viewtopic.php?f=3&t=50632&p=344803

FAQs: Button-code: How-to Copy Share Paste a button ('TOTALCMD#BAR#DATA')
https://ghisler.ch/board/viewtopic.php?f=3&t=50633&p=335879

FAQs: User-Defined Command (UDC) (usercmd.ini) em_command
https://ghisler.ch/board/viewtopic.php?p=344777#p344777


- - -







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"

- - -

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd
/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).

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy
xcopy "source.doc" "c:\targetFolder\" (targetFolder will be created, don't forget the trailing backslash)

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/copy
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 >>> https://ghisler.ch/board/viewtopic.php?f=2&t=52423
English FAQs >>>>> FAQs: Summary - Tips & Tricks collection >>>>> https://ghisler.ch/board/viewtopic.php?f=3&t=52425



 
Post Reply