Created
November 15, 2023 21:27
-
-
Save Saniee/1c1bb939e096a9574d06bfd35f9ff8ec to your computer and use it in GitHub Desktop.
AutoHotkey 2.0 Script for launching favorite programs with hotkeys. Completely Customizable, even down to opening of the config hotkey.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires AutoHotkey v2.0 | |
#SingleInstance force | |
configPath := A_ScriptDir "\programHotkeysConfig.ini" | |
if (FileExist(configPath)) { | |
prg1 := IniRead(configPath, "Programs", "prg1Value") | |
prg2 := IniRead(configPath, "Programs", "prg2Value") | |
prg3 := IniRead(configPath, "Programs", "prg3Value") | |
prg4 := IniRead(configPath, "Programs", "prg4Value") | |
Prg1Hotkeyold := IniRead(configPath, "Hotkeys", "prg1Hotkey") | |
Prg2Hotkeyold := IniRead(configPath, "Hotkeys", "prg2Hotkey") | |
Prg3Hotkeyold := IniRead(configPath, "Hotkeys", "prg3Hotkey") | |
Prg4Hotkeyold := IniRead(configPath, "Hotkeys", "prg4Hotkey") | |
guiHotkeyOld := IniRead(configPath, "Hotkeys", "guiHotkey") | |
} else { | |
prg1 := "" | |
prg2 := "" | |
prg3 := "" | |
prg4 := "" | |
Prg1Hotkeyold := "!a" | |
Prg2Hotkeyold := "!b" | |
Prg3Hotkeyold := "!c" | |
Prg4Hotkeyold := "!d" | |
guiHotkeyOld := "!+c" | |
} | |
Hotkey Prg1Hotkeyold, runPrg1 | |
Hotkey Prg2Hotkeyold, runPrg2 | |
Hotkey Prg3Hotkeyold, runPrg3 | |
Hotkey Prg4Hotkeyold, runPrg4 | |
Hotkey guiHotkeyOld, OpenGui | |
MainGui := Gui(, "PH Config") | |
Tab := MainGui.AddTab3("w240 h235", ["Hotkeys", "Programs"]) | |
Tab.UseTab() | |
guiHotkey := MainGui.AddHotkey(, guiHotkeyOld) | |
updateguiHotBtn := MainGui.AddButton("x135 y246", "Update GUI Hotkey") | |
saveSettingsBtn := MainGui.AddButton("x8", "Save Settings") | |
Tab.UseTab(1) | |
MainGui.AddText("x20 y38", "Program-1 Hotkey:") | |
prg1Hotkey := MainGui.AddHotkey("x120 y35", Prg1Hotkeyold) | |
MainGui.AddText("x20 y76", "Program-2 Hotkey:") | |
prg2Hotkey := MainGui.AddHotkey("x120 y76", Prg2Hotkeyold) | |
MainGui.AddText("x20 y114", "Program-3 Hotkey:") | |
prg3Hotkey := MainGui.AddHotkey("x120 y114", Prg3Hotkeyold) | |
MainGui.AddText("x20 y152", "Program-4 Hotkey:") | |
prg4Hotkey := MainGui.AddHotkey("x120 y152", Prg4Hotkeyold) | |
updateHotkeysBtn := MainGui.AddButton("x20 y185", "Update Hotkeys") | |
Tab.UseTab(2) | |
prg1Edit := MainGui.AddEdit("x20 y38") | |
prg1Btn := MainGui.AddButton("x140 y37", "Choose Program-1") | |
prg2Edit := MainGui.AddEdit("x20 y76") | |
prg2Btn := MainGui.AddButton("x140 y75", "Choose Program-2") | |
prg3Edit := MainGui.AddEdit("x20 y114") | |
prg3Btn := MainGui.AddButton("x140 y113", "Choose Program-3") | |
prg4Edit := MainGui.AddEdit("x20 y152") | |
prg4Btn := MainGui.AddButton("x140 y151", "Choose Program-4") | |
updateProgramsBtn := MainGui.AddButton("x20 y185", "Update Programs") | |
MainGui.AddText("x20 y210", "Use this when you edited only the Text Boxes.") | |
MainGui.Show("w250 h300") | |
updateHotkeysBtn.OnEvent("Click", UpdateHotkeys) | |
updateProgramsBtn.OnEvent("Click", updatePrograms) | |
prg1Btn.OnEvent("Click", editPrg1) | |
prg2Btn.OnEvent("Click", editPrg2) | |
prg3Btn.OnEvent("Click", editPrg3) | |
prg4Btn.OnEvent("Click", editPrg4) | |
updateguiHotBtn.OnEvent("Click", updateGuiHotkey) | |
saveSettingsBtn.OnEvent("Click", SaveSettings) | |
if (FileExist(configPath)) { | |
prg1Edit.Text := prg1 | |
prg2Edit.Text := prg2 | |
prg3Edit.Text := prg3 | |
prg4Edit.Text := prg4 | |
} | |
; Open the Gui for config | |
OpenGui(*) { | |
MainGui.Show("w250 h275") | |
} | |
; Update hotkeys | |
UpdateHotkeys(*) { | |
global Prg1Hotkeyold, Prg2Hotkeyold, Prg3Hotkeyold, Prg4Hotkeyold | |
Hotkey Prg1Hotkeyold, "Off" | |
Prg1Hotkeyold := prg1Hotkey.Value | |
Hotkey Prg2Hotkeyold, "Off" | |
Prg2Hotkeyold := prg2Hotkey.Value | |
Hotkey Prg3Hotkeyold, "Off" | |
Prg3Hotkeyold := prg3Hotkey.Value | |
Hotkey Prg4Hotkeyold, "Off" | |
Prg4Hotkeyold := prg4Hotkey.Value | |
Hotkey prg1Hotkey.Value, runPrg1 | |
Hotkey prg2Hotkey.Value, runPrg2 | |
Hotkey prg3Hotkey.Value, runPrg3 | |
Hotkey prg4Hotkey.Value, runPrg4 | |
Hotkey prg1Hotkey.Value, , "On" | |
Hotkey prg2Hotkey.Value, , "On" | |
Hotkey prg3Hotkey.Value, , "On" | |
Hotkey prg4Hotkey.Value, , "On" | |
if (Hotkey(prg1Hotkey.Value)) { | |
} | |
} | |
; Update Programs with the EditBoxes | |
updatePrograms(*) { | |
global prg1, prg2, prg3, prg4 | |
prg1 := prg1Edit.Text | |
prg2 := prg2Edit.Text | |
prg3 := prg3Edit.Text | |
prg4 := prg4Edit.Text | |
} | |
; Edit Program 1 Path | |
editPrg1(*) { | |
global prg1 | |
f := FileSelect() | |
prg1Edit.Text := f | |
prg1 := f | |
} | |
; Edit Program 2 Path | |
editPrg2(*) { | |
global prg2 | |
f := FileSelect() | |
prg2Edit.Text := f | |
prg2 := f | |
} | |
; Edit Program 3 Path | |
editPrg3(*) { | |
global prg3 | |
f := FileSelect() | |
prg3Edit.Text := f | |
prg3 := f | |
} | |
; Edit Program 4 Path | |
editPrg4(*) { | |
global prg4 | |
f := FileSelect() | |
prg4Edit.Text := f | |
prg4 := f | |
} | |
; Run Program 1 | |
runPrg1(*) { | |
global prg1 | |
Run Format('"{1}"', prg1) | |
} | |
; Run Program 2 | |
runPrg2(*) { | |
global prg2 | |
Run Format('"{1}"', prg2) | |
} | |
; Run Program 3 | |
runPrg3(*) { | |
global prg3 | |
Run Format('"{1}"', prg3) | |
} | |
; Run Program 4 | |
runPrg4(*) { | |
global prg4 | |
Run Format('"{1}"', prg4) | |
} | |
; Update the Gui Open Hotkey | |
updateGuiHotkey(*) { | |
global guiHotkeyOld | |
Hotkey guiHotkeyOld, "Off" | |
guiHotkeyOld := guiHotkey.Value | |
Hotkey guiHotkey.Value, OpenGui | |
} | |
SaveSettings(*) { | |
global prg1, prg2, prg3, prg4 | |
configPath := A_ScriptDir "\programHotkeysConfig.ini" | |
if (!FileExist(configPath)) { | |
FileAppend "Hotkey Edit Help`n! - Alt, + - Shift, ^ - Ctrl, # - Windows Key`n{Example, #N - Activates on pressing Windows + N}`n`n", configPath | |
} | |
; Save Program Paths | |
IniWrite prg1, configPath, "Programs", "prg1Value" | |
IniWrite prg2, configPath, "Programs", "prg2Value" | |
IniWrite prg3, configPath, "Programs", "prg3Value" | |
IniWrite prg4, configPath, "Programs", "prg4Value" | |
; Save Hotkeys | |
IniWrite prg1Hotkey.Value, configPath, "Hotkeys", "prg1Hotkey" | |
IniWrite prg2Hotkey.Value, configPath, "Hotkeys", "prg2Hotkey" | |
IniWrite prg3Hotkey.Value, configPath, "Hotkeys", "prg3Hotkey" | |
IniWrite prg4Hotkey.Value, configPath, "Hotkeys", "prg4Hotkey" | |
IniWrite guiHotkey.Value, configPath, "Hotkeys", "guiHotkey" | |
If (!InStr(FileExist(configPath), "H")) { | |
FileSetAttrib("+H", configPath) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment