Script to shut down PC after 30 minutes idle triggered at startup Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SyntaxTerror
Posts: 53
Joined: 23 May 2017, 12:55

Script to shut down PC after 30 minutes idle triggered at startup

Post by SyntaxTerror » 09 Jan 2022, 12:45

Hello

I adapted a little script to shutdown my PC after 30 minutes of inactivity (no keyboard or mouse action detected with A_TimeIdle), but sometimes when I start my PC, I see the first window saying that it will shut down in 5 minutes (i.e. there have been no mouse/keyboard action detected for 1800000 ms/30 minutes).

I haven't made tests yet, , but I'm thinking of setting A_TimeIdle to 0 (but I don't know if I it will work), or maybe make the script move the mouse a little so it will reset A_TimeIdle.

Is there is a better way to avoid this ?

My script:

Code: Select all

#SingleInstance Force
#NoEnv
#Persistent

SetTimer, Arret, 250
return

Arret:
If (A_TimeIdle > 1800000)
MsgBox,, >>                Arrêt automatique (Auto Shutdown)               <<, L'ordinateur va s'éteindre dans 5 minutes. (The computer will shut down in 5 minutes)`n`nCliquer sur OK pour annuler. (Click OK to abort),60
If (A_TimeIdle > 1860000)
MsgBox,, >>                Arrêt automatique               <<, L'ordinateur va s'éteindre dans 4 minutes.`n`nCliquer sur OK pour annuler.,60
If (A_TimeIdle > 1920000)
MsgBox,, >>                Arrêt automatique               <<, L'ordinateur va s'éteindre dans 3 minutes.`n`nCliquer sur OK pour annuler.,60
If (A_TimeIdle > 1980000)
MsgBox,, >>                Arrêt automatique               <<, L'ordinateur va s'éteindre dans 2 minutes.`n`nCliquer sur OK pour annuler.,60
If (A_TimeIdle > 2040000)
MsgBox,, >>                Arrêt automatique               <<, L'ordinateur va s'éteindre dans 1 minute.`n`nCliquer sur OK pour annuler.,60
If (A_TimeIdle > 2100000)
Shutdown, 12
Return
Thank you for your time.

User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: Script to shut down PC after 30 minutes idle triggered at startup

Post by mikeyww » 09 Jan 2022, 12:50

Although I have not tested it, you might want to add a Sleep of 1-2 minutes at the start of the script. I think I would also use A_TimeIdlePhysical to measure the idle time. You don't set AHK's built-in variables; you read them. Try a shutdown flag of 8. Change timer frequency to 60000. I think I would use "Else If", "Between", or "Switch" instead of "If".

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Script to shut down PC after 30 minutes idle triggered at startup

Post by flyingDman » 09 Jan 2022, 18:13

I would initially set the timer at say 10 minutes and then reset it it (inside the label) to a higher frequency (although 250 ms is excessive, every 10 seconds for this seems OK)
14.3 & 1.3.7

User avatar
SyntaxTerror
Posts: 53
Joined: 23 May 2017, 12:55

Re: Script to shut down PC after 30 minutes idle triggered at startup  Topic is solved

Post by SyntaxTerror » 13 Apr 2024, 08:25

Sorry for the (very) late reply.

I solved the problem by adding MouseMove 940, 560 at the beginning.

Post Reply

Return to “Ask for Help (v1)”