Script for shutdown

Hi All,

I did not try this concept but here i explain the situation below.

Situation: Someone is working in the mac machine but they fail to switch off their machine. I need a script for shutdown the system automatically if the system is not disturbed for last 10 minutes.

Please have a look and help in these regards…

Thanks
Elansezhian

I know there’s a unix command to check the idle time of a machine. People have used it in scripts before so you can do a search to find it. Then you need the shutdown command which is:

tell application “System Events” to shut down

Hi Elansezhian,

try this, save it as stay open application


property triggerTime : 10 * minutes

on idle
	set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
	if idleTime > triggerTime then tell application "System Events" to shut down
	return 60
end idle

G’day stefan,

Thanks for your help.

I try the above and i saved this as you mentioned here it waits for the user response for quit the opened applications (software).

Actually what i need is, i am working in MAC machine and i am opened so many applications, in this occasion suppose if i am not disturbed my system for 5 minutes my system will get shutdown automatically without asking anything for opened applications.

All will performed inside the script itself, here we did not do any manual work or it does not wait for the user response. Once the system is not disturbed for 5 minutes my system get shutdown without any indications.

Thanks
Elansezhian

what’s about this?


property triggerTime : 10 * minutes

on idle
	set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
	if idleTime > triggerTime then do shell script "shutdown -h now" password "¢¢¢¢¢¢" with administrator privileges
	return 60
end idle