Opening Files from the Command Line

Opening Files from the Command Line

One of the great things about using the Unix command line in Mac OS X is that you are also using a Macintosh. So how do you access graphical Mac applications or AppleScripts from the command line? Apple provides a set of command-line tools to do exactly that.

To "double-click" a file from the command line:

  • open filename

    The open command performs the equivalent of double-clicking each of its arguments. For example,

    open *.doc FunReport

    is the same as double-clicking all the .doc files in the current directory, along with the file FunReport. The default application for each file is used just as if you had double-clicked the icons in the Finder.

Tips

  • You can specify which application to use with the -a switch (or option)for example,

    open -a "BBEdit 6.5" found_files

    would open the file called found_files using the BBEdit 6.5 application.

  • The open command is often used to open the current directory in the Finder:

    open .


To run an AppleScript from the command line:

  • osascript scriptname

    The osascript command executes the script named by its argument.

Tip

  • If you are an experienced AppleScript programmer, read the Unix manual page for osascript by typing

    man osascript

    You will also be interested in learning about the osacompile and osalang commands.


The Importance of Editing Text in Unix

Editing text from the command line is a crucial part of using Unix.

Unix system-configuration files, system-startup files, source code for software, and much documentation are all contained in text files, which you will have occasion to edit when using the command line.

While you can certainly use your favorite Aqua text editor or word processor to edit text in Mac OS X, you will need to be able to edit files directly from the command line if you do any serious command-line work. Also, if you want to be able to use other Unix systems besides Mac OS X, you will need to learn how to edit files using one of the command-line tools.

Chapter 6, "Editing and Printing Files," teaches you the basics of using the most common command-line text editor, the vi editor. In this chapter, you will use the simpler pico / nano editor, which is adequate for the example of creating a shell script but is not appropriate for more complex Unix work, such as editing system-startup files. (The nano editor is a compatible replacement for the more well-known pico editor, but nano has a less restrictive license and more features. On Mac OS X 10.4 the pico command actually runs nano .)




Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net