Sometimes restarting is not enough: you need to power off your Mac, wait for a little, and power it on again.
I'm looking for a script which does just that. Is it possible?
It could be a script which act like the "schedule" program in system preferences: it would switch off the Mac immediately, the add 1 minute to the current time and switch it on again.
Do you think it's possible?
I haven't tested this, so it may take some tweaking (I'm suspicious of the 'quoted form of' bits, because I don't know if pmset requires double quotes), but it should work. basically it tells the power management system (pmset) to schedule a one-time shutdown in 1 minute and a one-time poweron in 2 minutes.
set shutdownTime to do shell script "date -v+1M '+%D %T'"
set restartTime to do shell script "date -v+2M '+%D %T'"
do shell script "pmset schedule shutdown " & quoted form of shutdownTime
do shell script "pmset schedule poweron " & quoted form of restartTime
If you have troubles it's almost certainly a matter of quoting. it might be easier in that case just to rewrite it as a plain shell script.