Runabout/runabout.ahk
2025-05-03 18:04:50 +07:00

317 lines
6.7 KiB
AutoHotkey

historyFile := "commandHistory.ini"
aliasFile := "alias.ini"
#r::
Gui, Add, Text,, Select an option:
Gui, Add, Button, gRunApp, &Run
Gui, Add, Button, gWebSearch, &Web
Gui, Add, Button, gAliasManager, Alias &Manager
Gui, Add, Button, gExit, &Exit
Gui, Show,, Select an Option
return
RunApp:
Gui, Destroy
Gui, Add, Text,, &Enter the command:
history := LoadHistory()
history := RTrim(history, "|")
Gui, Add, ComboBox, vRunCommand, %history%
Gui, Add, Button, gBrowseFile, &Browse
Gui, Add, Button, gExecuteCommand, &Run
Gui, Add, Button, gExecuteAdminCommand, Run &as Administrator
Gui, Add, Button, gCancelRun, &Cancel
Gui, Show,, Run Command
return
WebSearch:
Gui, Destroy
Gui, Add, Text,, &Enter a Google search query:
Gui, Add, Edit, vSearchQuery
Gui, Add, Button, gExecuteSearch, &OK
Gui, Add, Button, gCancelWeb, &Cancel
Gui, Show,, Web Search
return
AliasManager:
Gui, Destroy
Gui, Add, Text,, Existing Aliases:
aliasList := LoadAlias()
; Create a checkbox list for aliases
aliasArray := StrSplit(aliasList, "|")
Loop, % aliasArray.MaxIndex()
{
Gui, Add, Checkbox, vCheckBox%A_Index%, % aliasArray[A_Index]
}
Gui, Add, Button, gAddAlias, &Add New Alias
Gui, Add, Button, gRemoveAlias, &Remove Selected Alias
Gui, Add, Button, gCancelAliasManager, &Cancel
Gui, Show,, Alias Manager
return
gAddAlias:
Goto AddAlias
AddAlias:
Gui, Destroy
Gui, Add, Text,, Enter &alias name:
Gui, Add, Edit, vAliasName
Gui, Add, Text,, &Enter command for the alias:
Gui, Add, Edit, vAliasCommand
Gui, Add, Button, gBrowseForAlias, Browse &File
Gui, Add, Button, gBrowseForFolder, Browse Fo&lder, Alt+O
Gui, Add, Button, gSaveAlias, &Save
Gui, Add, Button, gCancelAlias, &Cancel
Gui, Show,, Add Alias
return
BrowseForAlias:
FileSelectFile, SelectedFileOrFolder, , , Select File, All Files (*.*)
if (SelectedFileOrFolder != "")
{
GuiControl,, AliasCommand, %SelectedFileOrFolder% ; Set hasil browse ke kotak edit AliasCommand
}
return
BrowseForFolder: ; Fungsi untuk Browse folder
FileSelectFolder, SelectedFolder, , , Select Folder
if (SelectedFolder != "")
{
GuiControl,, AliasCommand, %SelectedFolder% ; Set hasil browse folder ke kotak edit AliasCommand
}
return
SaveAlias:
Gui, Submit
if (AliasName = "" or AliasCommand = "")
{
MsgBox, Alias name or command cannot be empty!
return
}
; Load current aliases, append new one, and save
currentAliases := LoadAlias()
if (currentAliases != "")
newAliases := currentAliases . "|"
else
newAliases := ""
newAliases .= AliasName "=" AliasCommand
IniWrite, %newAliases%, %aliasFile%, Aliases
MsgBox, Alias added successfully!
Goto AliasManager
return
RemoveAlias:
selectedAliases := ""
aliasArray := StrSplit(LoadAlias(), "|")
Loop, % aliasArray.MaxIndex()
{
GuiControlGet, isChecked, , CheckBox%A_Index% ; Get the checkbox status
if (isChecked) ; If the checkbox is checked
{
aliasName := aliasArray[A_Index]
selectedAliases .= aliasName . "|"
}
}
if (selectedAliases = "")
{
MsgBox, Please select an alias to remove!
return
}
MsgBox, 4, Confirm Delete, Are you sure you want to delete the following aliases:n%selectedAliases%
IfMsgBox Yes
{
; Load current aliases and filter out the selected ones
aliasArray := StrSplit(LoadAlias(), "|")
remainingAliases := ""
Loop, % aliasArray.MaxIndex()
{
aliasEntry := aliasArray[A_Index]
aliasName := StrSplit(aliasEntry, "=").1 ; Extract the alias name
if !InStr(selectedAliases, aliasName) ; If alias is not selected for deletion
{
if (remainingAliases != "")
remainingAliases .= "|"
remainingAliases .= aliasEntry
}
}
IniWrite, %remainingAliases%, %aliasFile%, Aliases
MsgBox, Selected aliases have been removed.
}
Goto AliasManager
return
CancelAlias:
Gui, Destroy
Goto AliasManager
return
CancelAliasManager:
Gui, Destroy
return
ExecuteCommand:
Gui, Submit
if (RunCommand = "")
{
MsgBox, Commands cannot be empty!
return
}
RunCommand := LoadAliasCommand(RunCommand) ; Check if command is an alias
If (RunCommand = "documents") {
Run, explorer.exe shell:Documents
} Else If (RunCommand = "downloads") {
Run, explorer.exe shell:Downloads
} Else If (RunCommand = "desktop") {
Run, explorer.exe shell:Desktop
} Else If FileExist(RunCommand)
{
if InStr(RunCommand, ".exe")
{
Run, %RunCommand%
}
else
{
Run, explorer.exe "%RunCommand%"
}
}
else
{
Run, %RunCommand%
}
SaveHistory(RunCommand)
Gui, Destroy
return
ExecuteAdminCommand:
Gui, Submit
if (RunCommand = "")
{
MsgBox, Commands cannot be empty!
return
}
if FileExist(RunCommand)
{
if InStr(RunCommand, ".exe")
{
Run, *RunAs %RunCommand%
}
else
{
Run, explorer.exe "%RunCommand%"
}
}
else
{
Run, *RunAs %RunCommand%
}
SaveHistory(RunCommand)
Gui, Destroy
return
CancelRun:
Gui, Destroy
return
CancelWeb:
Gui, Destroy
return
BrowseFile:
FileSelectFile, SelectedFile, , , Select File, All Files (*.*)
if SelectedFile !=
{
if InStr(SelectedFile, ".exe")
{
Run, %SelectedFile%
}
else
{
Run, explorer.exe "%SelectedFile%"
}
SaveHistory(SelectedFile)
}
return
ExecuteSearch:
Gui, Submit
Run, https://www.google.com/search?q=%SearchQuery%
Gui, Destroy
return
SaveHistory(command) {
global historyFile
if command != ""
{
IniRead, previousHistory, %historyFile%, History, Commands
if (previousHistory != "ERROR") {
previousHistory := StrReplace(previousHistory, command . "|", "")
previousHistory := StrReplace(previousHistory, "|" . command, "")
previousHistory := StrReplace(previousHistory, command, "")
newHistory := command
if (previousHistory != "")
newHistory := newHistory . "|" . previousHistory
IniWrite, %newHistory%, %historyFile%, History, Commands
}
else
{
IniWrite, %command%, %historyFile%, History, Commands
}
}
}
LoadHistory() {
global historyFile
if FileExist(historyFile)
{
IniRead, history, %historyFile%, History, Commands
if (history = "ERROR" or history = "")
return ""
return history
}
else
{
return ""
}
}
LoadAlias() {
global aliasFile
if FileExist(aliasFile)
{
IniRead, aliasList, %aliasFile%, Aliases
if (aliasList = "ERROR" or aliasList = "")
return ""
return aliasList
}
else
{
return ""
}
}
LoadAliasCommand(alias) {
global aliasFile
IniRead, command, %aliasFile%, Aliases, %alias%
if command != "ERROR"
return command
return alias
}
Exit:
Gui, Destroy
return
#^+r::ExitApp