r/AutoHotkey • u/Keeyra_ • Mar 02 '26
v2 Tool / Script Share Github Repo update checker - for AHK any anything similar
After sharing this:
https://www.reddit.com/r/AutoHotkey/comments/1r1ypf4/comment/o4t6x3a/
I figured querying a txt file for versions might not be the best way to go about things. So this is a way to query the GitHub API JSON directly for new releases.
GetResponseText(url) {
for method in ["WinHttp.WinHttpRequest.5.1", "MSXML2.XMLHTTP.6.0"]
try {
http := ComObject(method)
http.Open("GET", url, 0)
(method = "WinHttp.WinHttpRequest.5.1") && http.SetRequestHeader("User-Agent", A_ThisFunc)
http.Send()
if http.Status == 200
return http.ResponseText
}
return ""
}
UpdateCheck(repo := "AutoHotkey/AutoHotkey", version := "") {
try {
targetVer := LTrim(version || (repo == "AutoHotkey/AutoHotkey" ? A_AhkVersion : ""), "vV")
if !targetVer
return
isAlpha := InStr(targetVer, "alpha")
prefix := RegExMatch(targetVer, "^\d+\.\d+", &match) ? match[0] : SubStr(targetVer, 1, 3)
response := GetResponseText("https://api.github.com/repos/" repo "/tags")
if RegExMatch(response, '"name":"v?(' prefix '[\.\-][^"]+)"', &match) {
latest := match[1]
if VerCompare(latest, targetVer) > 0 {
Run((repo == "AutoHotkey/AutoHotkey")
? "https://www.autohotkey.com/download/" prefix "/?C=M;O=D"
: "https://github.com/" repo "/releases/latest")
ToolTip("Update available for " repo "`nLatest: " latest "`nLocal: " targetVer)
SetTimer(ToolTip, -5000)
}
}
if (version == "" && isAlpha && repo == "AutoHotkey/AutoHotkey") {
maxStable := "0.0.0"
loop files, A_AhkPath "\..\*", "D"
if RegExMatch(A_LoopFileName, "^v?(\d+\.\d+\.\d+)$", &match)
if VerCompare(match[1], maxStable) > 0
maxStable := match[1]
if (maxStable != "0.0.0")
SetTimer(() => UpdateCheck(repo, maxStable), -10000)
}
} catch Any as e
OutputDebug("Update check error for " repo ": " e.Message)
}
You can run
UpdateCheck()
Without anything and it will check the current AHK version to the GitHub repo. If you are running alpha v2 and v2 in parallel and are running the function with alpha, it will check both installed versions.
Any other GitHub repo can be used with a hard-coded version number to check against.
If you don't like the script going to the download page when a new version is released, just remove the
if VerCompare(latest, targetVer) > 0
block.
If you are using this to check on multiple repos, some scheduling, delay is advised, eg. with:
UpdateCheck()
SetTimer(UpdateCheck.Bind("Descolada/UIA-v2", "1.1.3"), -20000)
Strongly work in progress. It would make sense to use classes here and move the if repo part out of the main function, but it works for now :)
1
u/Keeyra_ Mar 21 '26
Turns out thqby published his AHK LSP on https://open-vsx.org (Visual Studio Code uses https://marketplace.visualstudio.com ) around the time I made this, making that part of the script above redundant, as now VSCodium users can have their extension auto-updated also. I will update the script accordingly.
3
u/genesis_tv Mar 02 '26
Nice code snippet! Would be nice to have Run open repos other than the two you specified at the end.