Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- #ifwinactive ahk_class Notepad++
- ^s::
- Send, ^s ;save
- WinGetTitle, currentTitle, A
- ;removes initial '*' if present on currentTitle(notepad++ adds '*' to title on change)
- StringLeft, firstChar, currentTitle, 1
- currentTitle := (firstChar = "*") ? SubStr(currentTitle,2) : currentTitle
- currentTitle := RegExReplace(currentTitle, " - Notepad\+\+") ;removes " - Notepad++" from active-window variable
- if(SubStr(currentTitle, StrLen(currentTitle) - 3) = ".ahk"){ ;if the variable has .ahk extension at end
- if (currentTitle != A_ScriptFullPath){ ;if the current active-window variable is not the same as THIS master script
- ;get the list of running AutoHotkey processes and stores it in 'allScripts'
- DetectHiddenWindows, On
- WinGet, listNum, List, ahk_class AutoHotkey
- allScripts := ""
- Loop % listNum {
- WinGetTitle, scriptTitle, % "ahk_id" listNum%A_Index%
- allScripts .= (allScripts ? "`n" : "") . RegExReplace(scriptTitle, " - AutoHotkey v[\.0-9]+$")
- }
- DetectHiddenWindows, Off
- ;if the "current" script is running
- if(InStr(allScripts, currentTitle)) {
- ;gets "current" script directory
- RegExMatch(currentTitle, "^(.+[\\/])", fileDir)
- StringTrimRight, fileDir, fileDir, 1 ;removes last '/'
- originalWorkingDir := A_WorkingDir ;stores THIS master script's initial working directory
- SetWorkingDir, %fileDir% ;and changes it to the "current" script directory (it'll be temporary)
- run, % currentTitle " /restart" ;restarts/reloads "current" script
- ;Optional tooltip
- ToolTip, % "Saved & Reloaded,`n" currentTitle
- Sleep 400
- ToolTip
- SetWorkingDir, %originalWorkingDir% ;restores THIS master script's initial working directory
- }
- }else{
- ;Optional tooltip
- ToolTip, Saved & Reloaded
- Sleep 200
- ToolTip
- Reload
- }
- }
- return
- #ifwinactive
Advertisement
Add Comment
Please, Sign In to add comment