Check AHK script for Run Time Errors by adding option to shift-Right click Menu

Post your working scripts, libraries and tools
julesverne
Posts: 13
Joined: 18 Apr 2017, 14:39
GitHub: JulesverneOnGitHub

Check AHK script for Run Time Errors by adding option to shift-Right click Menu

19 Aug 2019, 13:14

Hi all, a need came up for this so I figured I'd share. I wanted to be able to check a script for run time errors without actually running the script. Then I figured I'd make it even easier on myself and use it for any ahk scripts by shift right clicking on an ahk file and selecting it from the menu. So I wrote a second script to add the first script to the registry.

All I did was adapt some code to a Lexikos script I found here: https://autohotkey.com/board/topic/129196-proper-error-handling-when-compiling-exit-code-and-stdout/ and in a separate file, a second bit of code to add it to the registry to allow the user to add it to the context menu (shift right click on an AHK file).

1. Save the first bit of code as RunTimeError_Verifier.ahk and save it wherever you like.

Code: Select all

path = %1%

SplitPath, path ,, OutDir,,,

FileAppend, % ValidateScript(path), % OutDir . "\RunTimeErrors.txt"

ValidateScript(path) {
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /iLib NUL /ErrorStdOut """ path """")
    return exec.StdErr.ReadAll()
}
2. Save the code below as AddVerifierToContextMenu.ahk but you must switch out the path I wrote (C:\Somepath) to the path where you saved RunTimeError_Verifier.ahk

Code: Select all

RegWrite, REG_SZ, HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\ValidateErrorCheck\Command, , cmd /c "C:\Somepath\RunTimeError_Verifier.ahk" %1
example:

Code: Select all

RegWrite, REG_SZ, HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\ValidateErrorCheck\Command, , cmd /c "C:\Users\%A_UserName%\Desktop\RunTimeError_Verifier.ahk" %1

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot], teadrinker and 58 guests