AutoHotkey: Popup-Menü für Buttons oder F4
Zur Navigation springen
Zur Suche springen
Übersicht
Dieses Script zeigt ein Popup-Menü mit in einer Konfigurationsdatei definierten Programmen an. Nach Klick auf einen Eintrag wird das gewählte Programm mit den definierten Parametern gestartet. Dies ist nützlich, um verschiedene externe Programme auf einen einzigen Button in der Knopfleiste zu legen oder um nach Drücken von F4 mehrere Editoren zur Auswahl zu haben.
Quelltext
<code>#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</code>