What is the alternate for BAT file (Windows) on Mac? Does different version of OS X have different format of BAT files? I am trying to create a BAT file on Mac which normally changes directory while the file is open.

  • Look here or here – Mathias711 Jun 15 '14 at 12:04
  • 2
    Look at Unix shell scripts or python, perl or other scripting languages – user151019 Jun 15 '14 at 12:26
  • 2
    Let's focus on general ways to do things similar to BAT files in this question. If you need help in getting a specific problem solved please ask a new question. – nohillside Jun 15 '14 at 15:13

Being pretty unfamiliar with batch files, I'm not sure of the functionality available, but there are two main scripting methods on OS X which are similar:

  • AppleScript

    AppleScript is a scripting language which lets you control OS X and many applications.

    AppleScripts are generally easy to understand and write whilst providing a lot of advanced functionality. Here is an AppleScript which counts the files in the Applications folder:

    tell application "Finder"
        if folder "Applications" of startup disk exists then
            return count files in folder "Applications" of startup disk
            return 0
        end if
    end tell

    For more information about AppleScript, see:

  • Shell script

    A shell script is a script for a Unix shell.

    The equivalent shell script to the above AppleScript is the following:

    if [ -d "/Applications/" ]; then
        ls -1 "/Applications/" | wc -l

    As you're probably going to use bash, this is a good guide to get you started:


Look up .bash or .command on mac ;)

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

You must log in to answer this question.

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