Launching a Mac OS X application from the Terminal

Discussion in 'Mac OS X' started by RHochstenbach, Apr 3, 2010.

  1. RHochstenbach

    RHochstenbach Administrator

    Likes Received:
    Trophy Points:
    An application in Mac OS X is basically a folder with the .app extension. If you browse inside it, there is a folder structure. Opening the folders Contents > MacOS reveals a UNIX Terminal file, which can be launched with the Terminal. If you're unsure about the name of the Terminal file? Just right-click (ctrl+click for one mouse button users) and choose 'Show Package Contents'. In there, just browse to Contents/MacOS.


    Why is this useful? Because you can edit configuration files with the Mac OS X Text Editor.

    For example, you want to edit your /etc/hosts file with the text editor. In that case, just enter this command (sudo used for root privileges):
    sudo /Applications/ /etc/hosts
    Like you might have noticed, the .app file and the terminal file are both called TextEdit. Even if you use a different system language, it's the same. So (unless you changed the Application's name) the names of both the .app folder and the terminal file are identical.

    And of course because Mac OS X is UNIX-based, you can even create aliases. In this example I create an alias named 'rootedit' to execute the Text Editor with Root Privileges:
    alias rootedit="]sudo /Applications/"
    Now if you want to edit a config file like /etc/hosts, just enter this command:
    rootedit /etc/hosts

Share This Page