Alanyyab

Save & Reload (Notepad++)

Jan 18th, 2023
976
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | Software | 1 0
  1. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2. #ifwinactive ahk_class Notepad++
  3. ^s::
  4. Send, ^s ;save
  5.  
  6. WinGetTitle, currentTitle, A
  7. ;removes initial '*' if present on currentTitle(notepad++ adds '*' to title on change)
  8. StringLeft, firstChar, currentTitle, 1
  9. currentTitle := (firstChar = "*") ? SubStr(currentTitle,2) : currentTitle
  10.  
  11. currentTitle := RegExReplace(currentTitle, " - Notepad\+\+") ;removes " - Notepad++" from active-window variable
  12. if(SubStr(currentTitle, StrLen(currentTitle) - 3) = ".ahk"){ ;if the variable has .ahk extension at end
  13. if (currentTitle != A_ScriptFullPath){ ;if the current active-window variable is not the same as THIS master script
  14.  
  15.  
  16. ;get the list of running AutoHotkey processes and stores it in 'allScripts'
  17. DetectHiddenWindows, On
  18. WinGet, listNum, List, ahk_class AutoHotkey
  19. allScripts := ""
  20. Loop % listNum {
  21. WinGetTitle, scriptTitle, % "ahk_id" listNum%A_Index%
  22. allScripts .= (allScripts ? "`n" : "") . RegExReplace(scriptTitle, " - AutoHotkey v[\.0-9]+$")
  23. }
  24. DetectHiddenWindows, Off
  25.  
  26. ;if the "current" script is running
  27. if(InStr(allScripts, currentTitle)) {
  28.  
  29. ;gets "current" script directory
  30. RegExMatch(currentTitle, "^(.+[\\/])", fileDir)
  31. StringTrimRight, fileDir, fileDir, 1 ;removes last '/'
  32.  
  33. originalWorkingDir := A_WorkingDir ;stores THIS master script's initial working directory
  34. SetWorkingDir, %fileDir% ;and changes it to the "current" script directory (it'll be temporary)
  35. run, % currentTitle " /restart" ;restarts/reloads "current" script
  36.  
  37. ;Optional tooltip
  38. ToolTip, % "Saved & Reloaded,`n" currentTitle
  39. Sleep 400
  40. ToolTip
  41.  
  42. SetWorkingDir, %originalWorkingDir% ;restores THIS master script's initial working directory
  43. }
  44.  
  45. }else{
  46. ;Optional tooltip
  47. ToolTip, Saved & Reloaded
  48. Sleep 200
  49. ToolTip
  50.  
  51. Reload
  52. }
  53. }
  54. return
  55.  
  56. #ifwinactive
Tags: ahk
Advertisement
Add Comment
Please, Sign In to add comment