the purpose of my question , I need someone to remotely turn off my device

because I wont be in front of my Laptop

I succeeded in giving him a terminal command to shutdown my PC

osascript -e 'tell app "System Events" to shut down'

but the issue here (the below image)

= there's opening apps which open a dialog (Terminate processes , would like to review) ?

and waiting for input/interaction from me

I wont be in front of my Laptop , so I need this solution to by force immediately shutdown the device without these dialogs - without depending on action by me

enter image description here

2 Answers 2


Easier, but sacrifices security

Create an admin account for him on the system.

Have him type

sudo -u his_short_user_name shutdown -h now

He then answers a password challenge with his password, and the system does a "somewhat hard" shutdown. This means apps will not be asked about saving application data, so your half finished Illustrator drawing is gone.

Better security

At Terminal, you write a bit of perl to wait for his shutdown request. You launch it after every reboot with sudo perl program_name. When you do, it'll challenge you for your password, and then run as superuser. When it comes time to shutdown, it's already authenticated so it just does it.

  my $signal_file = "/Users/(you)/Public/Drop Box/shutdown";
  unlink ($signal_file); 

  while (1) { 
    next if not -f $signal_file;
    system ”shutdown -h now";

And your guest needs to simply touch '/Users/(you)/Public/Drop Box/shutdown' to trigger a shutdown. He doesn't need any special rights to do this. For instance you could publish your Public directory as a network share point, a perfectly reasonable thing to do from a security POV.

If you want to temporarily prevent a user from doing this, either kill the process (ctrl-C) or create a directory there called shutdown. Note that perl is testing for -f (presence of file).


Use the following command:

sudo shutdown -h now

This will kill all open processes and shut down the Mac, without any warnings shown.

  • it's same my friend , because this command will ask for interaction - input from me my MAC password
    – 27mdmo7sn
    Aug 26, 2019 at 17:58
  • @27mdmo7sn Yes - it will ask for interaction, but not locally on the physical machine. Your friend who is logging in remotely will enter the password on their machine, your Mac will then shut down. This does require that the remote user (your friend) has access to an admin account on the machine.
    – Scot
    Aug 26, 2019 at 18:20

You must log in to answer this question.

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