Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
Look here or here –  Mathias711 Jun 15 at 12:04
2  
Look at Unix shell scripts or python, perl or other scripting languages –  Mark Jun 15 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. –  patrix Jun 15 at 15:13

1 Answer 1

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
        else
            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
    fi
    

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

share|improve this answer

Your Answer

 
discard

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.