Skip to content

Instantly share code, notes, and snippets.

@estasney
Created October 1, 2021 17:23
Show Gist options
  • Save estasney/d6352cd84280a0c5b6e89d577f8930f1 to your computer and use it in GitHub Desktop.
Save estasney/d6352cd84280a0c5b6e89d577f8930f1 to your computer and use it in GitHub Desktop.
GUI Script Runner
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir C:\path\to\scripts\folder
padX := 10 ; X Padding Between Buttons
padY := 10 ; Y Padding Between Buttons
nCols := 3 ; Number of Columns
btnWidth := 150 ; Width of Buttons
btnHeight := 100 ; Height of Buttons
ScriptName :=""
FileListMsg :=""
FileNameReadable :=""
Readable2File := {}
cX :=0
cY :=0
colIdx :=0
rowIdx :=0
ReadableFile(x) {
; split by '_', title case and remove file ext for display name
temp := StrReplace(x, ".bat", "")
temp := StrReplace(temp, "_", " ")
StringUpper, temp, temp, T
return temp
}
Gui, +AlwaysOnTop -SysMenu
Gui, FileGui: Font, s14 cRed norm, Lucida Console
Loop Files, *.bat, F
{
FileNameReadable := ReadableFile(A_LoopFileName)
FileListMsg .= FileNameReadable "|"
Readable2File[FileNameReadable] := A_LoopFileName
}
For k, v in Readable2File
{
if (colIdx >= nCols) {
colIdx := 0
rowIdx := rowIdx + 1
}
cX := (btnWidth * colIdx)
cY := (btnHeight * rowIdx)
cX := cX + ( padX * colIdx)
cY := cY + ( padY * rowIdx)
Gui, FileGui:Add, Button, x%Cx% y%Cy% w%btnWidth% h%btnHeight% gAccepted, %k%
colIdx := colIdx + 1
}
Gui, FileGui:Show
Return ; Wait for click
GuiEscape:
ExitApp
GuiClose:
ExitApp
Accepted:
ScriptName := Readable2File[A_GuiControl]
Run, "%ScriptName%", .
ExitApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment