Quit Terminal after Running SSH "shutdown" Apple (Shell) Script for Remote Machine

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


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 &"