Autohotkey Script to shutdown & restart Local App (helps keep correct time)

Started by dRdoS7, February 20, 2017, 02:08:00 AM

Previous topic - Next topic

dRdoS7

Hi,

I got tired of the LA on my Win 7 machine falling behind the Classic, so I wrote a script for Autohotkey. Actually I modified one I used to have at work to log my PC off at home time, in case I was in too much of a hurry to remember!

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
#Persistent ; If this directive is present anywhere in the script, that script will stay running after the auto-execute section (top part of the script) completes. This is useful in cases where a script contains timers.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetTimer, UpdateClock, 30000
Return

UpdateClock:
  If (A_Hour=05 and A_Min=55) {
    GoSub, Ask
    Sleep, 60000
  }
  If (A_Hour=11 and A_Min=55) {
    GoSub, Ask
    Sleep, 60000
  }
  If (A_Hour=17 and A_Min=55) {
    GoSub, Ask
    Sleep, 60000
  }
Return

Ask:
  MsgBox, 4, It's time!!!, Shutdown LA?, 5
  IfMsgBox Timeout
    GoSub RestartLA
  else
    MsgBox,,, You pressed NO., 5
Return

RestartLA:
^!l::
IfWinExist, MidNite Solar Status Panel
{
MsgBox,,, Local App found,5
    WinClose ; use the window found above
Sleep 5000
IfWinExist, MidNite Solar Status Panel
    {
MsgBox,,, MidNite Solar Status Panel is not closed.,5
}
Else
{
MsgBox,,, MidNite Solar Status Panel is now closed.,5
}
Run, C:\Program Files\MidNite Solar\LocalStatusPanel\LocalStatusPanel.exe
Sleep 10000 ; Time to reopen and connect
IfWinExist, MidNite Solar Status Panel
    {
MsgBox,,, MidNite Solar Status Panel is now Open.,5
Sleep, 10000
MouseClick, left, 600, 60
}
return
}


If you don't have AHK, it's a free download, and is a great scripting language. Just copy the text into Notepad or NP++ and save with an .ahk ext. Then run the file. It restarts LA 3 times a day, LA does MN itself. It can be auto started with Windows. just put a shortcut to the file in Startup.

It will action 3 times a day, but it can be modified to any, and as many, times you'd like.

dRdoS7

mike90045

Since I only use the LA once or twice a day, I've not seen a daily drift in time.   Does this solve a problem where the LA being chatty with the Classic, causes the classic clock to drift by stealing time ticks away as comms duty ?
http://tinyurl.com/LMR-Solar

Classic 200| 2Kw PV, 160Voc | Grundfos 10 SO5-9 with 3 wire Franklin Electric motor (1/2hp 240V 1ph )| Listeroid 6/1, st5 gen head | XW6048 inverter/chgr | midnight ePanel & 4 SPDs | 48V, 800A NiFe battery bank | MS-TS-MPPT60 w/3Kw PV

dRdoS7

Hi,

Quote from: mike90045 on February 20, 2017, 10:39:10 AM
Since I only use the LA once or twice a day, I've not seen a daily drift in time.   Does this solve a problem where the LA being chatty with the Classic, causes the classic clock to drift by stealing time ticks away as comms duty ?

FIIK!

LA is always running on a PC. Classic internal clock pretty much keeps time with the PC it's connected to. LA always drops behind both of them, and it's about 20mins out before MN. I only noticed it when I was looking at the graph (quite a whille ago - can't rush these things!), and noticed it ended well before MN, which is when the clock must reset itself. I don't have Auto Reset enabled.

I should have added, that once running, it can be invoked manually by pressing CTL-ALT-l at any time. Also, the messages (I used them to check the sequence) can be disabled by placing a ";" at the start of a line. There is a "mouse click" which does "View", but I've found it only works sometimes, maybe because I access the PC via RDP.

dRdoS7.