How to remotely shut down a Mac with AppleScript

Here’s a couple of simple AppleScripts to help you quickly shut down a Mac. This is handy if you are using it as a media center and want to shut down cleanly with one click, without picking up the keyboard or mouse, without logging in via Apple Remote Desktop, and without prompting for a password. I find a two-app approach works best as it gives you the flexibility to have a one-click dock icon on the target Mac as well as on the Mac you’re on, without too much redundancy.

Step 1 – Create on the target Mac (the one you want to shut down). Replace password with your own. Save the script as an Application package in your Applications folder.

do shell script "shutdown -h now" password "password" with administrator privileges

Step 2 – On the target Mac, enable Remote Apple Events in the Sharing System Preference pane.

Step 3 – Create a different on your Mac. This app just tells the to open on your target Mac. Replace user, password & targethost with your own values. 502 is the uid of the user on the target Mac – the same user who’s credentials you used in the first You can find this out by opening Terminal and running the “id” command. Save the script in your Applications folder as an Application package, then place on your Dock.

set s to "eppc://user:password@targethost/Finder?uid=502"
using terms from application "Finder"
    tell application s to open application file "Macintosh"
end using terms from

If you like, change the icon in the .app package to something nice, you can Google how to do that 😉

Leave a Reply