title: Script to shutdown mac
body: <p>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.</p>
  
  <p>Thanks</p>
  
  <p>Ok,</p>
  
  <p>This is the applescript  code im using to shutdown may mac. I've added it as an iCal event thats runs nightly.</p>
  
  <pre><code>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 \"" &amp; this_process &amp; "\""
          end if
      end repeat
  on error
      tell the current application to display dialog "An error has occurred!" &amp; return &amp; "This script will now quit" buttons {"Quit"} default button 1 with icon 0
  end try
  
  
  
  tell application "System Events"
      shut down
  end tell
  </code></pre>