Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to shutdown mac

I'm trying to automate the shutdown of my mac, I've tried the scheduled shutdown in energy saver and I wanna sleep but these don;t seem to work. VLC player runnign seems to prevent the shutdown. I think I need a script to forcefully shutdown the mac regardless of of what errors may thrown to screen by various programs running.

Thanks

Ok,

This is the applescript code im using to shutdown may mac. I've added it as an iCal event thats runs nightly.

tell application "System Events" to set the visible of every process to true

set white_list to {"Finder"}

try
    tell application "Finder"
        set process_list to the name of every process whose visible is true
    end tell
    repeat with i from 1 to (number of items in process_list)
        set this_process to item i of the process_list
        if this_process is not in white_list then
            do shell script "killall \"" & this_process & "\""
        end if
    end repeat
on error
    tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try



tell application "System Events"
    shut down
end tell
like image 206
blue-sky Avatar asked May 02 '26 16:05

blue-sky


2 Answers

Could you try a simple applescript, which goes something like this...

tell application "System Events"
shut down
end tell

See if it works, and then you can make it run through Automator at certain time, etc.

like image 107
notthetup Avatar answered May 05 '26 05:05

notthetup


my solution (somwhat late). Just a bash script with apple in it:


#!/bin/bash
# OK, just shutdown all ... applications after n minutes
sudo shutdown -h +2 &
# Try normal shutdown in the meantime
osascript -e 'tell application "System Events" to shut down'

I also edited the /etc/sudoers (and /private/etc/sudoers) file(s) and added the line: ALL=NOPASSWD: /sbin/shutdown

Always worked for me for an assured shutdown (knock knock ;-) )

like image 36
job Avatar answered May 05 '26 07:05

job