2

I have helped a few friends recently with fixing a problem on OS X and I would like to turn it in to a script so I can send it to people instead of walking them through it. It consists of two steps:

  • delete a file
  • restart the computer

What is the best way to package this so people will be able to execute it with the default security settings on Mountain Lion and Mavericks? AppleScript, Automator, Shell script?

0

AppleScript is imho the best one for your case. Shell needs sudo for shutdown -r and automator is overkill for these basic needs.

Here are the 2 basic scripts you'll need :

To reboot :

tell application "Finder"
  restart
end tell

To delete a file :

tell application "Finder" to delete file "path:to:file"

If you want to use a posix path, an alternative to the previous one is

tell application "Finder" to delete POSIX path of "/path/to/file"
  • Thank you. What if I need to find the file based on a pattern, something I might normally use ls or a regexp for? – emkman Nov 28 '13 at 3:06
  • 1
    You can call shell scripts within AppleScript using do shell script. – Matthieu Riegler Nov 28 '13 at 3:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .