Tuesday 24 September 2013

AppleScript: Shut Down or Restart Your MacBook with Linux Shell Scripting

The following Linux Shell script allows you to shut down or restart your MacBook with a simple click. You can also use the script with any MacBook management software (eg. Casper) to remind your users to shut down or restart their machine.

<<Script>>

#!/bin/bash
VARIABLE=$(/usr/bin/osascript <<-EOF
tell application "System Events"
                activate
                set question to display dialog "The machine has not been shut down or restarted for more than a week. Please shut down or restart the machine by clicking on Shut Down or Restart." with title "System Event by Andres Cheah, MCM" buttons {"Shut Down", "Restart", "Cancel"} with icon caution
                set answer to button returned of question
                if answer is equal to "Shut Down" then
                                tell application "System Events"
                                                shut down
                                end tell
                end if
                if answer is equal to "Restart" then
                                tell application "System Events"
                                                restart
                                end tell
                end if
                if answer is equal to "Cancel" then
                                return
                end if
end tell
EOF)

No comments:

Post a Comment