Skip to content

Instantly share code, notes, and snippets.

@jmbeach
Last active August 25, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmbeach/0bddd12bbebc19835536 to your computer and use it in GitHub Desktop.
Save jmbeach/0bddd12bbebc19835536 to your computer and use it in GitHub Desktop.
AutoHotkey Console Log/WriteLine Equivalent
;Inspired by thread:http://www.autohotkey.com/board/topic/103338-best-way-for-debug/?hl=%2Bconsole+%2Blog#entry638264
;Based on script by user Hachi.
;Edit by Jared Beach.
;
; #include this script in a script you want to debug.
; "#Include, ./debug.ahk"
;
; Add debug messages by writing `debug("your message here")`
;
; See live debug messages by running:
; AutoHotkey myscript.ahk debug | Write-Host
; Exit the script by pressing Win + x.
;//////////////////////////////////////////////////////////////////
; Determine if this is a debug session
Gosub, SubCheckDebugArgs
; Works regardless if debug argument is passed in.
debug(string) {
string .= "`n"
FileAppend %string%,* ;* goes to stdout
}
; win + x ends script so you can see output in command-line
#x::
{
if (isDebug = true) {
Gosub, SubExit
}
Return
}
SubExit:
{
ExitApp ;Terminate for debug
}
SubCheckDebugArgs:
{
isDebug := false
i := 0
Loop %0% { ; for all commandline arguments
param = %A_Index%
if (%param% = "debug") {
isDebug := true
}
}
Return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment