Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote the following very simple script:

route -n add
route -n delete
route -n add

And would like to just double click it and you know... run it... on windows 8 i would just have to save as a .bat and right click it-> run as admin... How can i achieve similar behavior in mac osx (latest version)?

Extra points if i can just double click it (cut the run under elevated mode)

share|improve this question
up vote 4 down vote accepted

Instead of .bat, save it as .command.

A .command file will run the contents of the file in Terminal upon double-click, just like a .bat would do on Windows.

If you can't run the file because you don't have permission to execute the command file, you need to set 'execute' on the file for it to allow you to run it:

chmod u+x /path/to/file.command

u is the owner of the file, +x adds 'execute', so u+x gives the owner of the file the ability to execute it

And to the the commands as admin, OS X always requires you to put in the admin password. For your script, the easiest way to do this, is to run the script as an admin user and change the script to the following:

sudo route -n add
sudo route -n delete
sudo route -n add

sudo stands for Substitute User DO and runs as root by default. It is likely sudo will ask for your password.

share|improve this answer
Almost there! permission issue blocking now! any ideas? and yes i'm in the admin group – Leonardo Jul 17 '14 at 16:16
@Leonardo Make sure you have permission to execute; see this question – grgarside Jul 17 '14 at 16:18
The permission problems are likely on the route command -- it needs sudo permissions to run. Try prefixing each line with sudo -A to get an interactive prompt for your password. – Ian C. Jul 17 '14 at 16:27
@ian-c, when I do a $ sudo -A date it returns: sudo: no askpass program specified, try setting SUDO_ASKPASS – CousinCocaine Jul 17 '14 at 17:20
Drop the -A then -- I thought OS X had a built-in asker application. – Ian C. Jul 17 '14 at 17:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.