How to specify command to always run as root?

In Mountain Lion, I frequently used a simple automator app called "Purge Memory" which just ran "purge" in the command line. I really enjoyed cleaning the RAM, especially when buggy apps ran memory leaks.

But now in Mavericks purge requires root privileges, breaking my app. I know I can open terminal and input it, but that is not nearly as convenient.

I have heard that on Unix you can allow a specific command to always run as root. That way I could automate purge. I would like to know if anyone knows how to do this or if this would even solve the problem?


You could use a Run AppleScript action that runs do shell script "purge" with administrator privileges. It requires entering a password though.

If you don't want to enter a password, add %localaccounts ALL=NOPASSWD: /usr/sbin/purge to sudoers. (Run sudo visudo, press i, type or paste the text, press escape, and type :wq.) Then use a Run Shell Script action that runs sudo purge.


I disagree about purging unused RAM being useless. I have 8GB of RAM, and when free RAM gets down to a several MBs, my Mac gets very sluggish, and it's even hard to switch Finder windows without it being really slow. The purge command fixes that right up.

Now Mavericks uses compressed memory, so you aren't supposed to need such things, but I still find that my Mac gets unresponsive when there is not enough free RAM. Typing "sudo purge" into terminal freed up 2GB of RAM, and things are nice and snappy again.