I have made a small apple script (calling a shell script using ssh) to remotely shutdown/hibernate my windows machine. I export the script as application so I can easily call it from my raycast search.

set question to display dialog "Are you sure you want to hibernate pDesktop?" buttons {"Yes", "No"} default button 1 with icon caution
set answer to button returned of question

if answer is equal to "Yes" then
    do shell script "ssh -t [email protected] 'shutdown.exe /h'"
end if

This works fine, however after executing the script (or even just the shell ssh command in a terminal), the terminal on mac os hangs (because the remote server closes the connection) and I have to kill the process.

Is there any method to prevent this? Or a better/recommended method to remotely send a shutdown command?

Thanks phil


2 Answers 2


You can try to run the command on the other host with nohup and in background (&) :

"nohup ssh -t [email protected] 'shutdown.exe /h’ &"

You may need to redirect output and error :

"nohup ssh -t [email protected] 'shutdown.exe /h’ >./nohup.out 2>./nohup.err &"
  • that worked like a charm! Thank you!
    – Phil
    Oct 6, 2021 at 21:46
  • hmmm it didn't work the second time I tried.
    – Phil
    Oct 7, 2021 at 6:43
  • I added redirection of output and error
    – Ptit Xav
    Oct 7, 2021 at 8:45
  • This asks me for quote? phil@Phil-MacBook:Scripts > nohup ssh -t [email protected] 'shutdown.exe /h’ >./nohup.out 2>./nohup.err & then quote>
    – Phil
    Oct 8, 2021 at 14:21
  • I tried to write it like to did but on iPhone the ´ and " characters may not be the one you must use. Use simple quote for the woman’s executed by ssh and double quote for the whole string. You can try to execute the nohup ommand from a terminal window on MacOS.
    – Ptit Xav
    Oct 8, 2021 at 15:12

I tried the suggested nohup ... & solution which did not work (it was asking for some input in the terminal and run as script it would still hangup). Then I tried the nohup ... >./nohup.out 2>./nohup.err & suggestion but simply nothing would happen.

So I played around with the different options trying to set countdown to hibernation to 1 second:

ssh -t [email protected] 'shutdown.exe /h /t 1' 

Unfortunately that did not work and I got an error message about stdin not being a terminal.

Because I did not only want to be able to hibernate my windows machine but also suspend it, I found the tool psshutdown.exe. I had the same problems that the terminal or the apple script would hang when executing the command over ssh with:

ssh -t [email protected] 'psshutdown.exe -h -t 0 -accepteula' 

note: the option -h here is for hibernate.

After playing around with different options I eventually found how I can make it work without hangup:

ssh -t [email protected] 'psshutdown.exe -h -t 1 -accepteula' 

I simply changed the countdown from 0 seconds (-t 0) to 1 second (-t 1). I guess the extra second allowed the script to terminate before the remote machine would close the connection and make the script hang. This works for both hibernating and suspending the windows computer. For the latter you simply have to exchange -h for -d:

ssh -t [email protected] 'psshutdown.exe -d -t 1 -accepteula' 

Hope this helps anyone else trying to do the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .