This script generates a popup menu with applications read from a configuration file. After clicking one of the entries, the chosen program will be launched with the specified parameters. This is useful to map different programs onto a single toolbar button or shortcut. It was specifically written for Total Commander.
#NoTrayIcon ;#ErrorStdOut SplitPath A_ScriptFullPath, null, IniDir, null, IniFile, null IniFile = %IniDir%\%IniFile%.ini IfNotExist %IniFile% { MsgBox Kann %IniFile% nicht finden. ExitApp } ProcessMenu("Menu") Menu Menu, Show Exit SplitFirst(ByRef OutLeft, ByRef OutRight, InpText, InpSep) { StringGetPos SepPos, InpText, %InpSep% If (SepPos >= 0) { StringLeft OutLeft, InpText, %SepPos% RemChars := StrLen(InpText)-SepPos-1 StringRight OutRight, InpText, %RemChars% } Else { OutLeft := InpText OutRight := "" } } ProcessMenu(Menu) { global IniFile IniRead MenuTitle, %IniFile%, %Menu%, Title If (MenuTitle <> "ERROR") { Menu %Menu%, Add, %MenuTitle%, AboutBox Menu %Menu%, Default, %MenuTitle% ; Menu %Menu%, Disable, %MenuTitle% Menu %Menu%, Add } IniRead Count, %IniFile%, %Menu%, MaxItem, 0 Loop %Count% { IniRead, CurItem, %IniFile%, %Menu%, %A_Index% If (CurItem = "-") Menu %Menu%, Add Else If (CurItem <> "ERROR") { SplitFirst(CurID, CurTitle, CurItem, "|") If (CurTitle = "") CurTitle := CurID IniRead IsSub, %IniFile%, %CurID%, MaxItem, 0 If (IsSub = 0) { Menu %Menu%, Add, %CurTitle%, ProcessEvent IniRead CurCmd, %IniFile%, %CurID%, Cmd If (CurCmd = "ERROR") Menu %Menu%, Disable, %CurTitle% } else { ProcessMenu(CurID) Menu %Menu%, Add, %CurTitle%, :%CurID% } IniRead IsChecked, %IniFile%, %CurID%, Checked, 0 If (IsChecked = 1) Menu %Menu%, Check, %CurTitle% } } Return } ProcessEvent: IniRead Count, %IniFile%, %A_ThisMenu%, MaxItem, 0 Loop %Count% { IniRead, CurItem, %IniFile%, %A_ThisMenu%, %A_Index% If (CurItem <> "ERROR") { SplitFirst(CurID, CurTitle, CurItem, "|") If (CurTitle = "") CurTitle := CurID If (CurTitle = A_ThisMenuItem) { IniRead Cmd, %IniFile%, %CurID%, Cmd If (Cmd <> "ERROR") { empty := "" IniRead TargDir, %IniFile%, %CurID%, StartPath, %empty% IniRead StartMode, %IniFile%, %CurID%, StartMode, %empty% Loop 9 { CurPar := %A_Index% StringReplace Cmd, Cmd, `%%A_Index%, %CurPar% } ; Use RunWait for ex. Total Commander, where the starting app has to know ; whether the launched app is still running. Otherwise use Run. RunWait %Cmd%, %TargDir%, %StartMode%, PID } } } } Return AboutBox: MsgBox 4160, Über ClickMenu..., ClickMenu zeigt ein Popup-Menü mit Einträgen, die aus einer INI-Datei ausgelesen werden und startet das gewählte Programm.`n`nMade in 2005 by Markus Birth <mbirth at webwriters.de> Return
To simplify the usage, it is recommended to compile the script using ahk2exe (contained in the AutoHotkey download). If the compiled script is named ClickMenu.exe, assign this file to a button in the Total Commander toolbar. Add all needed parameters (up to 9) into the Parameter field. These can be used later in the ClickMenu.ini with %1…%9. Alternatively you can assign the ClickMenu.exe to the F4 button to get a selection of different editors.
The whole configuration takes place through an INI file, which has to have the same basename of the script or executable file. In this example, the INI file has to be named ClickMenu.ini.
An example INI file looks like this:
[Menu] ;Maximum number to parse, starting at 1 ;Empty values are ignored. MaxItem=99 Title=blafasel 1=TE1|Test entry 2=- 3=TES|Test sub 4=TE3|Test sub2 [TE1] Cmd=notepad.exe %1 ;Checked=1 ; (omit following to start in current path) StartPath=C:\TEMP ; StartMode=(Max|Min|Hide) ; (omit following to start normally) StartMode=Max [TES] ;Checked=1 MaxItem=1 1=TE2|Test2 entry [TE2] Cmd=explorer.exe [TE3] MaxItem=1 1=TE2|Test2 entry again
The section [Menu] contains the main menu which is displayed after launching ClickMenu.exe. Every menu has one or more entries with a numeric key from 1 to n. (Format: key=value) The numbering doesn't have to be continuous, but the value of MaxItem has to be that of the highest key, i.e. entries with a key higher than MaxItem are NOT displayed. Also note that all entries are displayed in order of the keys from min to max.
Each menu can have a title which is defined through the key Title. This title is displayed in bold style above the entries.
Each menu item has the format x=section|title where x is the numeric key, section the section of that entry and title the title displayed in the menu.
A separator is added by x=-.
Program- and submenu-sections can also contain Checked=1 to display a checkmark in front of them.
To define a program to launch, the syntax is Cmd=program.exe /parameter. You can use supplied parameters like in the following line: Cmd=program.exe %3. This would run the file program.exe with the third parameter given to ClickMenu.exe.
To get a checkmark in front of the menu entry, add Checked=1 to the section.
Additionally you can set StartPath=c:\WINDOWS to run the program from this folder. Also there are StartMode=Max, StartMode=Min and StartMode=Hide which run the program maximized, minimized or hidden. If you omit StartPath the program gets run from the current directory. If you omit StartMode, it will be launched normally.