title: Running script with admin permissions on OS X
body: <p>I've tried my best to find out a solution with the many script questions on Stack Overflow and the internet, but I can't seem to find the solution I need.</p>
  
  <p>What I want to do is create a more automated and less clicking solution to remove all the Mobile cached user accounts on a system.  I've been logging in and manually going to user accounts and removing the users one at a time by clicking the "-" button, then clicking "Delete Immediately" for the user data.  This works, but is time consuming and I have better things to do with my time.  So I knew there had to be a way to do this with a script.  </p>
  
  <p>I ran across this code:</p>
  
  <pre><code>for cuser in `dscl . -list /Users AuthenticationAuthority | grep LocalCachedUser | awk '{print $1}' | tr '/n' ' '`; do
      dscl . -delete /Users/$cuser
  done
  </code></pre>
  
  <p>If I run this in terminal I get permission errors.  So I figured I need to run it with sudo.  So I started looking into creating AppleScripts to run the script, but I can't seem to find the right way to do it.</p>
  
  <p>Any ideas?  By the way, I'm new to scripting on the Mac, so please comment your code so I know whats happening, and so I don't just run some script code without know what it'll do. :)</p>
  
  <p>Thanks</p>