openThe open command performs multiple tasks. The following subsections give an overview, consult the man page for complete documentation:
man openIf you use open programmatically (instead of interactively via a shell) then it helps to know the long forms of the options. You can list those by calling open without any arguments.
open and filesYou can use open to work with files:
- Open a folder in the Finder:
- Open a file in the application that has been associated with it (which can be overridden per file):
- Reveal a file in the Finder (instead of opening it):
open -R index.html
- Open a file with a given application:
open -a firefox index.html
open and URLsopen also works with URLs:
- Open a URL:
- Open a mailto: URL to generate an email:
open 'mailto:email@example.com?subject=Hi&body=Hi%20Joe!'Check  for details.
open and text editorsopen sometimes uses the default text editor. That editor can be configured via the “Get Info” window: Open it for a .txt file, change the ”Open with” app to your liking, click “Change all...”. The current mappings can be looked up in the file
~/Library/Preferences/com.apple.LaunchServices.plistAn answer on Super User provides more information on what is going on here.
open has the following options for working with text editors:
- Open a file in TextEdit:
open -e README.md
- Open a file with the default text editor:
open -t README.md
- Read stdin, open the result in the default text editor. For example, the following command reads input from the keyboard and puts what you have typed in new window.
open -fAnother example: open the text “Hello World!” in a new window.
echo 'Hello World!' | open -fOn my system, -f always used TextEdit, so your mileage may vary.
osascriptosascript is a command that allows you to execute AppleScript code via the shell. Many things under Mac OS X can only be automated via AppleScript (Finder, iTunes, ...). For example, jsreload  uses the following code to reload the first tab of Chrome:
tell application "Google Chrome" tell tab 1 of window 1 to reload end tellTo execute that code on a Bash command line, type:
osascript <<-END tell application "Google Chrome" tell tab 1 of window 1 to reload end tell END
pbpaste and pbcopypbpaste and pbcopy interact with the clipboard (pb is short for “pasteboard”). pbpaste writes the clipboard to stdout, pbcopy replaces the clipboard with what it receives via stdin.
Example – changing the clipboard (e.g. if the current content of the clipboard is the plain text "Hello World", then it becomes "Hell- W-rld").
pbpaste | sed -e s/o/-/g | pbcopyExample – writing the clipboard to a text file: