script - What scripting/programming languages are default on Mac OSX?

07
2014-07
  • JKirchartz

    I was wondering what programming or scripting languages come pre-installed on OSX? Particularly programs that can be run from the command line.

    I'm planning on parsing some CSS, and outputting an html page. I've done it in python before, but I would like to make sure it's transferrable to others in my organization.

  • Answers
  • Gordon Davisson

    OS X doesn't come with any compilers built-in. It has a number of scripting languages though:

    • Python (2.7.2)
    • Perl (5.12.4)
    • Ruby (1.8.7p358)
    • PHP (5.3.15)
    • Bash (3.2)
    • Zsh (4.3.11)
    • AWK

    The listed versions are included in OS X Mountain Lion (v10.8), but some version of each of these has been included in OS X since at least v10.3.


  • Related Question

    terminal - Mac OSX: simple script wanted
  • Jason S

    I'm looking for a simple script that will do the following. Can anyone take a shot at it (+ if cryptic please explain what it does), or give me some pointers so I can run this myself?

    I want to start up a GUI app in the Applications directory from the command line prompt, giving it parameters if necessary:

    $> launch Foobar arg1 arg2 arg3
    

    What the launch shell script should do is:

    1) read a configuration file that looks something like this:

    /Applications/$0.app
    /Applications/$0
    /Applications/**/$0.app
    /Applications/**/$0
    

    2) try to match the first argument ("Foobar") in this case with each line of the config file, in order, with "*" representing any sequence of characters in a path segment and "**" representing any path segment, and $0 representing the program name. So in this case it's looking for Foobar.app and Foobar in the Applications directory and any of its subdirectories.

    3) execute the resulting command with the remaining arguments as specified ("arg1", "arg2", "arg3")

    Sounds easy but I'm too much of a newbie with shell scripts at the moment. I may end up using JSDB since I know how to use it, just not sure how to specify that a script called "launch" should require the JSDB program to run it, or whether it's compatible with doing that.

    edit: specific use case: If I'm in a directory within the command prompt, I often want to do one of the following:

    • launch TextEdit to create a new file named X
    • launch TextEdit to open a file named X
    • launch {name your favorite program} to create or open a file named X
    • open a Finder window in this directory

    edit 2: In particular, I wanted to edit my Mercurial .hg/hgrc file yesterday, and it took me forever to figure out how, since .hg is a directory that's hidden from GUI file-open dialog boxes. I still don't remember how I got it to work. 8-(


  • Related Answers
  • Ted Naleid

    "open" is the command you want. Use this to see the open options

    open -h
    

    You'll see that to open something in textedit, just use -e

    open -e foo.txt
    

    if it doesn't exist, just "touch" the file and open it:

    touch foo.txt 
    open -e foo.txt
    

    There are other applications out there (like textmate) that I think are better GUI editors that install their own command line command (ie: mate) that can automatically create files.

    To open the current file with the default editor, just don't pass any switched. So if .txt files are associated on your system with TextEdit, just using "open foo.txt" should work. Since directories are automatically associated with Finder, just use

    open .
    

    to open the current directory up in finder.

  • jtb

    One quick way of launching a GUI app from the Terminal it to just use open -a AppName. But you can't pass along command line arguments that way.

    However, it seems like the minority of programs even accept command line arguments, it would be crazy to require the user to write a script like this just to use them. GUI apps that do accept command line arguments usually have shell scripts in the PATH to handle them, for example mvim.

    Could you provide a more specific example of what you hope this script would achieve?

  • jtbandes

    You might be able to get what using mdfind, but I agree with jtb that a more specific example would be useful. Why do you want to do this?