Mac Open File With App Command Line
Must Read: Quitting Apps on Mac Just Got Handier! View Hidden Files and Folders: Now that you have accessed Terminal. Type or copy/paste the following commands into the Terminal window: “defaults write com.apple.finder AppleShowAllFiles TRUE” (This command tells the Finder to show all files, irrespective of the hidden flag setting ). Use similar commands specifying the application location and name followed by “.app” to open any application on your Mac. Open Folder in Terminal. Conversely, if you are in a folder in Finder and want to open it in Terminal, you can easily add a right-click shortcut to do so. Related: How to Add Options to macOS’s Services Menu.
- Mac Open File With App Command Lines
- Mac Commands List
- Mac Install Pkg Command Line
- Unzip From Command Line Mac
- Mac Terminal Open File
You may already be familiar with the open command in Darwin (OS X’s flavor of Unix). It allows you to open files and URLs in their default app or one that you specify. In its simplest form:
Those will open the url or file in whatever you have set as the default browser or editor for Markdown files. You can specify what application to use with -a, or by Bundle Identifier using -b.
You can also use it with application-specific urls, such as Dash’s dash: handler (I’ve detailed this before):
These are the uses most people who use the command are familiar with. You can open an app without a document with just the -a or -b flags, too. I alias open -a to just o on my system, so I can just type o tweetbot and launch the app. I’ve also set up bash completion for this. Pc apps on mac.
A fresh start
A couple of lesser-known features are pretty handy. First, the -F switch opens the specified application “fresh,” meaning no “persistent” windows are restored. Note that this erases the “persistent state” of the app, but leaves unsaved “Untitled” documents alone. It’s a great shortcut for opening an app that may have a document crashing it when it first opens. It doesn’t always work, but it’s usually the first thing I try in those situations. It’s just so easy.
Opening piped input
The -f command takes input from a STDIN pipe, creates a temporary file with it, then opens that in the specified app. You may have seen this yesterday in my tip for opening man pages in Preview. That trick uses PostScript output, but you can do the same with any type of data. Here’s a trick for pasting your current clipboard text to Marked.
Of course, Marked 2 can do that with just ⌘⇧V, so it’s less handy. Here’s a better one: combine a bunch of Markdown files in a folder into one temporary document with Markdown horizontal rules between them. I use this to quickly view all of my QuickQuestion answers from my nvALT folder (these filenames always start with “??”, adjust as needed):
The awk trick is kind of cool on its own. When you just use cat, you don’t get any separation between files, meaning that using it for Markdown output isn’t great. The command awk 'FNR1{print 'n---n1' will take all of the input files and print them with --- and newlines (or whatever you specify in the print command) between each one.
Editors
The -e switch causes open to automatically use TextEdit. A better option would be -t, which allegedly uses your default editor for text files, as determined by LaunchServices. Unfortunately, that always still opens TextEdit for me. Instead, I just alias edit to my $EDITOR script. You can also use the -W switch to cause open to wait for the opened application to exit before exiting the command. The -n switch causes a new instance of the application to open – even if the app is already running – so the combination of -Wn effectively turns any app into a valid $EDITOR setting.
Finder
In Spotlight, hitting ⌘↩ (Command Return) on a selected file reveals it in Finder instead of opening it. open has a -R switch that does the same. You could always use open -a Finder [filename], too. I have open -a Finder aliased to f, so I can just type f filename or f . to open a file, folder, or the current directory in Finder.
Other handiness
Mac Open File With App Command Lines
The -g flag is another handy one. It will open the target application in the background, so it doesn’t steal window focus. I find this especially handy if I’m using iTerm2 in visor mode, allowing me to open links and web pages without having the visor slide up. If you use something like Choosy, opening a URL directly can cause the visor window to lose focus, but the Choosy popup to disappear immediately as focus switches. I alias chrome and safari to use the open -g -a [appname] in order to bypass Choosy when necessary.

Cocoa developers should check out the -h option, but I won’t go into it here.
Lastly, you can pass arguments to an app specified with -a or -b using the --args flag. Anything after that flag will be passed as arguments to the application, not the open command.
The open command is one of OS X’s special gems. You won’t find it on other flavors of Unix. Cherish it.
Ryan Irelan has produced a series of shell trick videos based on BrettTerpstra.com posts. Readers can get 10% off using the coupon code TERPSTRA.
Terminal User Guide
You can use the command-line environment interactively by typing a command and waiting for a result, or you can use the shell to compose scripts that run without direct interaction.
Execute commands in the shell
In the Terminal app on your Mac, enter the complete pathname of the tool’s executable file, followed by any needed arguments, then press Return.
If a command is located in one of the shell’s known folders, you can omit path information when entering the command name. The list of known folders is stored in the shell’s PATH environment variable and includes the folders containing most command-line tools.
For example, to run the ls command in the current user’s home folder, enter the following at the command prompt, then press Return:
To run a command in the current user’s home folder, precede it with the folder specifier. For example, to run MyCommandLineProg, use the following:
% ~/MyCommandLineProg
To open an app, use the open command:
When entering commands, if you get the message command not found, check your spelling. Here’s an example:
Mac Commands List
% opne -a TextEdit.app zsh: opne: command not foundTerminate commands
In the Terminal app on your Mac, click the Terminal window that is running the command you want to terminate.
Press Control-C.
This sends a signal that causes most commands to terminate.
Repeat previously entered commands
Mac Install Pkg Command Line
The commands you enter during a session are saved so you can repeat a previously used command without retyping it.
Unzip From Command Line Mac
In the Terminal app on your Mac, press the Up Arrow key.
The last command you entered appears on the command line.
Continue pressing the Up Arrow key until you see the command you want, then press Return.