Shut Down, with 'User Sharing this Computer' dialog

Can anyone help me with a script to Shut Down a Mac, which is being used as a Time Machine ‘Share’ and which therefore has other - ‘Users Sharing this Computer’ and which consequently throws up a Dialog prior to Shut Down asking whether or not to proceed? Obviously, being on another Mac, I don’t see and can’t click the Dialog button.

image


(A little further info, in case someone might suggest a better way of doing this:

Firstly, I want to shut down the Mac, simply to save it running needlessly overnight. It can run for 24h or alternatively… 8h.

I have it scheduled to Shut Down and Startup at given times (via System Prefs/Settings).

In an attempt to workaround this hiccup, I’ve scheduled an Event in Calendar to run daily. This Event runs an ‘Open File’ Alert and the file I use is an Automator App, of a simple AppleScript, but it doesn’t work well. (I’m not a scripter, so it’s code I’ve found). The problem is either that the Dialog remains, or somewhat bizarrely, the Mac shuts down ok, but when started again, it does its startup, then it shuts down again. After that it’s ok.

I also tried re-starting via script, to simply clear the Alert Dialog, but even more bizarrely, it worked, but the Mac restarted 3 times.)

You need to separate the two themes. The former is “How to force the computer to shut down” and the latter is “How to run a bootup and shutdown script with the timer tool”.

Formar is easy.

do shell script “/sbin/halt” user name “yourAdminUserName” password “yourAdminPassword” with administrator privileges

This script shutdown your computer immediately.

Latter is not so strange or difficult theme. You can find the way.

Thank you very much for your reply Piyomaru.

I can’t get this to work (I have no idea what I’m doing with Shell/Terminal).

I get these errors from the script as below:

shellScript-error Small

shellScript Medium

Perhaps I should just be running it in an Automator’s Shell Script step?

Automator-ShelScript

Those are the wrong quotes ”
You are using typographer quotes,
When you should be using regular quotes. "
This usually happens when you copy/paste code from websites

Piyomaru didn’t format his code properly for the website. When posting code you are supposed to put 3 ticks (```) on a separate line before and after the code.
When done correctly, a button “Open in Script Editor” will appear below the code

And…“do shell script” commnd does not need to write inside Terminal.app’s tell block.

Thank you both for the replies.

I’m still getting an error. I’ve copied the text into TextEdit and converted to plain-text, to ensure there’s no odd characters, but I’m still getting this:

shellScript-error-2

shellScript-2

Where is the ‘do shell script’ command?
You do not use a tell terminal.

Try

do shell script "*/sbin/halt" user name "myname" password "mypassword" with administrator privileges

do shell script is in “StandardAdditions”.

Here is a ‘do shell script’ command I’ve used n the past to shutdown my Mac

do shell script “shutdown -r now” password “password” with administrator privileges

And this one below does. A better job of giving processes time to cleanup and quit

Tell application "login window" to «event aevtrest»

This will restart without asking
I believe the shutdown is «event aevtshut»

Tell application "login window" to «event aevtshut»

Thank you Robertfern, Piyomaru.

I misunderstood your post Piyomaru, which is why I removed the ‘do shell script’. Putting it back fixed the problem.

Robertfern, this is very interesting what you’re saying about the actual shutdown command and alternatives. One of the questions lingering in my mind was about how this shell command was shutting down the Mac? Since it’s primarily being used for Time Machine, it’s really important that the shutdown process allows Time Machine to clean up elegantly, if it happens to be in the middle of running a backup. I realise this process is built-in with 2 belts and 2 braces, but all the same, I wanted to be certain. To this end, I’ve added a couple of actions into the Automator app, to first Eject the TM disk, pause for a couple of minutes, then proceed with the shut down. I had some problems with the TM disk not mounting reliably on restart, but adding it to the User’s Login items solved this problem. So… so far so good.

Having said all that, I’d still be very interested to understand the pros and cons of the 3 methods that have been suggested.