Skip to content

Instantly share code, notes, and snippets.

@dansmith65
Created November 8, 2018 22:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dansmith65/290496063fa1d4ede56cf43f1950c93d to your computer and use it in GitHub Desktop.
Save dansmith65/290496063fa1d4ede56cf43f1950c93d to your computer and use it in GitHub Desktop.
Snippets from my main AutoHotkey script to load scripts from a folder, and close them when the main script exists.
OnExit, ExitSub
;AUTO LOAD SCRIPTS
;==============================================================================
Loop, AutoHotkey.d\*.ahk
{
OutputVarPID =
Run, %A_AhkPath% "%A_LoopFileFullPath%", , , OutputVarPID
CloseProcessesOnExit = %CloseProcessesOnExit%%OutputVarPID%`n
}
; will need hotkey's or something here to keep the script running, otherwise it will immediately exit and close the auto-loaded scripts
;SUBROUTINES
;==============================================================================
;RUN BEFORE EXITING THE SCRIPT
ExitSub:
Loop, parse, CloseProcessesOnExit, `n
If A_LoopField
{
; the if statement filters out the last empty value (created by a trailing `n)
Process, Close, %A_LoopField%
;If (%ErrorLevel% != %A_LoopField%)
; MsgBox, A sub-process could not be closed: %A_LoopField%
}
ExitApp
@dansmith65
Copy link
Author

Referenced in a comment here: https://portableapps.com/node/39299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment