simple auto shutdown script

Post your working scripts, libraries and tools for AHK v1.1 and older
ration
Posts: 18
Joined: 21 May 2016, 23:03

simple auto shutdown script

31 Aug 2016, 09:55

i ended up working a bit more on this script and i figured since it's pretty much polished by now (from my pov) maybe other people would find it useful as well.

Code: Select all

#persistent
#singleinstance force
#NoEnv

IfExist, %A_MyDocuments%\auto shutdown -er settings.ini
{
	Loop
	{
		FileReadLine, line%A_Index%, %A_MyDocuments%\auto shutdown -er settings.ini, %A_Index%
			If ErrorLevel
		        break
	}
}

Gui, New
Gui, Submit, NoHide
Gui, Add, Text,y1 Center cBlack vWinText , Welcome to ration's auto shutdown -er!
Gui, Add, Tab, w270 h200, General|Tips
Gui, Font, s14, Calibri
Gui, Add, Text, x12 y60, I shall check every
Gui, Add, Edit, x155 y59 w35 h27 number VSeconds ,%line1%
Gui, Font, S12
Gui, Add, DropDownList, x195 y57 w80 vTimeUnit , Minutes||Hours
Gui, Font, S14
Gui, Add, Text, x20 y95, and shut down
Gui, Add, Edit, x155 y95 w35 h27 number VSeconds2 ,%line2%
Gui, Font, S14
Gui, Add, Text,  x194 y96, (min) after 
Gui, Add, Button, default x17 y130 w255 h30, OK
Gui, Add, Text, x14 y165, Tip: Move the mouse to stop the`n shutdown after it triggers.
Gui Tab, Tip
Gui, Font, S12
Gui, Add, Text, x16 y40,This program will check for mouse `nmovements.`n    If you don't move the mouse`nfor the amount of time you set in the `nfirst box, a shutdown schedule will start.`n    You will have the "and shuts down ...  `nafter" amount of minutes  to move the`nmouse, which will make the the cycle `nreset and stop the shutdown.
Gui, Submit, NoHide
Gui, Show, w290 h230, Auto shutdown -er
Menu, Tray, add, Change_Settings
return

Change_Settings:
Run %A_ScriptFullPath%
Return

GuiSize:
GuiControl, MoveDraw, WinText, x0 w%A_GuiWidth%
Return

GuiClose:
Gui, Hide
ExitApp

ButtonOK:
Gui, Submit
IfExist, %A_MyDocuments%\auto shutdown -er settings.ini
	{
	FileDelete, %A_MyDocuments%\auto shutdown -er settings.ini
	}
FileAppend,
(
%Seconds%
%seconds2%
), %A_MyDocuments%\auto shutdown -er settings.ini




If (TimeUnit = "Minutes")
{
	waitA := Seconds * 1000 * 60
}
If (TimeUnit = "Hours")
{
	waitA := Seconds * 1000 * 60 * 60
}
waitB := Seconds2 * 60


CoordMode, Mouse, Screen

 

Loop1:
Loop
{
	AX:=""
	AY:=""
	BX:=""
	BY:=""
	MouseGetPos, AX, AY
	Sleep, %waitA%
	MouseGetPos, BX, BY
	Sleep, 500
	If ((AX=BX) and (AY=BY))
	{
		Run, Shutdown.exe  -s -t %waitB%, %A_WinDir%\System32\
		gosub, Loop2
	}
}

Loop2:
Loop
{
	AX:=""
	AY:=""
	BX:=""
	BY:=""
	MouseGetPos, AX, AY
	Sleep, 500
	MouseGetPos, BX, BY
	Sleep, 100
	If ((AX!=BX!) and (AY!=BY))
	{
		Run, Shutdown.exe -a, %A_WinDir%\System32\
		gosub, Loop1
	}
}


also, it saves the last input.
21.09 update : added change options in the tray icon options and fixed the second time var. (i forgot i used a defined var in the run first run command, changed it to user defined)
Last edited by ration on 21 Sep 2016, 16:20, edited 6 times in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: simple auto shutdown script

03 Sep 2016, 06:55

Thanks for sharing.
I'm sure your script is fine, however, you might be intrested in the built in variables A_TimeIdle and A_TimeIdlePhysical for future use.
ration
Posts: 18
Joined: 21 May 2016, 23:03

Re: simple auto shutdown script

03 Sep 2016, 10:48

Helgef wrote:Thanks for sharing.
I'm sure your script is fine, however, you might be intrested in the built in variables A_TimeIdle and A_TimeIdlePhysical for future use.
thanks for the suggestion, i wasn't aware of those, but i definitely see why you suggested them.i'll change up the version i use and leave the one posted as it is.
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: simple auto shutdown script

08 Sep 2016, 05:27

great script! tnx
ration
Posts: 18
Joined: 21 May 2016, 23:03

Re: simple auto shutdown script

21 Sep 2016, 15:55

Tomer wrote:great script! tnx
thanks, i recently updated it, so you might want to check that out

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 100 guests