Advertisement
rfancella

User Functions.ahk (IdleVol)

Mar 15th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. ; Use this function to define any code you want to run in every module on start
  2. StartGlobalUserFeatures(){
  3. Global systemName, 3rdPartyToolsSettingsFile, IdleVolPath, IdleVolUse
  4. Log("StartGlobalUserFeatures - Starting")
  5. 3rdPartyToolsSettingsFile := A_ScriptDir . "\Lib\3rdPartyToolsPaths.ini"
  6. Log("3rdPartyTools - Ini file location " . 3rdPartyToolsSettingsFile, 5)
  7. Log("IdleVolAdjust - Start IdleVolAdjust Section")
  8.  
  9. IdleVolPath := IniReadCheck(3rdPartyToolsSettingsFile, "IdleVolAdjust", "IdleVolPath",A_ScriptDir . "\IdleVolumeAdjuster.exe",,1)
  10. IdleVolUse := IniReadCheck(3rdPartyToolsSettingsFile, "IdleVolAdjust", "IdleVolUse","No",,1)
  11. IdleVolSystems := IniReadCheck(3rdPartyToolsSettingsFile, "IdleVolAdjust", "IdleVolSystems","",,1)
  12.  
  13. If !(FileExist(IdleVolPath)) {
  14. Log("IdleVolAdjust - Exe NOT located at " . IdleVolPath . ". Please check your paths", 5)
  15. IdleVolUse := "No"
  16. } else {
  17. IfInString, IdleVolSystems, %systemName%
  18. {
  19. Log("IdleVolAdjust - " . systemName . " System found in IdleVolSystems list", 5)
  20. If (IdleVolUse = "Yes") {
  21. Log("IdleVolAdjust - Running IdleVolumeAdjuster pause with """ . IdleVolPath . " pause""", 5)
  22. Run, % IdleVolPath . " pause",,UseErrorLevel,OutputVarPID
  23. } else If (IdleVolUse = "Kill") {
  24. Log("IdleVolAdjust - Running IdleVolumeAdjuster Kill with """ . IdleVolPath . " Kill""", 5)
  25. Log("IdleVolAdjust - Trying to detect if program is running.",5)
  26. Process, Exist, IdleVolumeAdjuster.exe
  27. IdleVolPID = %ErrorLevel%
  28. Log("IdleVolAdjust - IdleVolPID = " . IdleVolPID,5)
  29. If IdleVolPID = 0
  30. {
  31. Log("IdleVolAdjust - Process does not exist. Not stopping the process and it will not be restarted.", 5)
  32. IdleVolUse := "No"
  33. } else {
  34. Log("IdleVolAdjust - Attempting to stop Idle Volume Adjuster with a PID of " . IdleVolPID,5)
  35. Process, Close, %IdleVolPID%
  36. CloseIdleVolPID = %ErrorLevel%
  37. Log("IdleVolAdjust - Close process ErrorLevel - " . CloseIdleVolPID,5)
  38. If (IdleVolPID = CloseIdleVolPID)
  39. {
  40. Log("IdleVolAdjust - Process closed OK.",5)
  41. } else {
  42. Log("IdleVolAdjust - Process not closed. Will not restart.",5)
  43. IdleVolUse := "No"
  44. }
  45. }
  46. }
  47. } else {
  48. Log("IdleVolAdjust - " . systemName . " System Not found in IdleVolSystems list :" . IdleVolSystems, 5)
  49. IdleVolUse := "No"
  50. }
  51. }
  52. Log("IdleVolAdjust - Stop IdleVolAdjust Section")
  53. Log("StartGlobalUserFeatures - Ending")
  54. }
  55.  
  56.  
  57. ; Use this function to define any code you may need to stop or clean up in every module on exit
  58. StopGlobalUserFeatures(){
  59. Global IdleVolPath, IdleVolUse
  60. Log("StopGlobalUserFeatures - Starting")
  61. Log("IdleVolAdjust - Start IdleVolAdjust resume section")
  62. If (IdleVolUse = "Yes") {
  63. Log("IdleVolAdjust - Running IdleVolumeAdjuster resume with """ . IdleVolPath . " resume""", 5)
  64. Run, % IdleVolPath . " resume",,UseErrorLevel,OutputVarPID
  65. } else If (IdleVolUse = "Kill") {
  66. Log("IdleVolAdjust - Running IdleVolumeAdjuster restart from Kill with """ . IdleVolPath . """", 5)
  67. Run, % IdleVolPath,,UseErrorLevel,OutputVarPID
  68. } else {
  69. Log("IdleVolAdjust - Not adjusting volume. IdleVolUse set to: " . IdleVolUse, 5)
  70. }
  71.  
  72. Log("IdleVolAdjust - Stop IdleVolAdjust resume section")
  73. Log("StopGlobalUserFeatures - Ending")
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement