You can learn more about using Terminal and the shell on macOS in my my book: “macOS Terminal and Shell” — Thank you!
Most Terminal users will know that
MacBook Pro 5,5, Mac OS X (10.6.6) Posted on Feb 11, 2011 11:49 PM. The shell command to open a file in TextEdit is open -e mytextfile.txt. I removed all TextEdit plist files and put them back one by one and TextEdit would not open. Therefore, I found the com.apple.textedit.plist file on my newer Macbook Pro 13 inch (2015) and copied it to my Macbook Pro 15 inch (2011) and now TextEdit opens just as it should! Both computers are running Sierra OS X 10.12.6.
will open the current working directory in a Finder window. (You, dear wonderful reader, know this because you read my previous post on Terminal-Finder Interaction.)
However, the open
command can do so much more.
Folders
Trivially, it cannot merely open the current working directory, but any path:
This can be used as a quick way to navigate to hidden directories.
You can also open multiple folders at once:
To clean up, you can option-click any close button in a Finder window to close all Finder windows. Or you can use the keyboard short cut ⌘⌥W.
Files
open
can also open files. In general you can think of open
as the command line equivalent of double-clicking a file or folder in Finder.
will open document.pdf
in the current working directory with the default application for PDF files (usually Preview). You can use this against multiple files as well:
will open all screenshot files (if any) in a viewer in the default application (Preview).
Applications
If you have changed the default application that handles a file type or want to override the default application, you can use the -a
option:
You can specify just the name of an application or the full path, i.e. /Applications/Preview.app
. If you need to be specific, you can also specify an application’s bundle identifier with -b com.apple.Preview
.
If you want to open a document but keep the application and the new document window in the background, use the -g
option.
Text Editors
There are two interesting special cases for designating applications:
will open a file with TextEdit.
will open a file with the default application for text files (.txt
file extensions) You can use the Finder Info panel to change the default application or, if you want more fine grained control use RCDefaultApp. In the default macOS config these are the same, but you can of course change the default app to your favourite text editor. (Many text editors, like BBEdit and Atom, have their own CLI tool, but if they don’t, you can use open -t
instead.)
You can even pipe text into open
with the -f
option:
You can set your $EDITOR
environment variable: EDITOR='open -tnW'; export EDITOR
and then command lines tools that expect text from an editor, like git commit
, will get the text from open
and thus your default text editor instead. The -n
option will actually open a new (sometimes second) instance of the application and the command line tool will resume when you quit this new instance. This a somewhat awkward workflow for Mac users. Many text editors provide a command line tool that may work better in these cases. For BBEdit the correct $EDITOR
value is bbedit -w --resume
.
Showing Files in Finder
If you are working on a file in Terminal and want to locate it in Finder, open
can do better than just opening the enclosing folder. It can select a given file as well:
Will open a Finder window with the enclosing folder of helloworld.swift
and select the file. (You can pass multiple files into open -R
but it will only select the last file in the list.)
URLs
Finally there is one more useful thing you can open
:
and, as always, you can use the -a
option to override the default application:
Header files
For the sake of being complete: you can also open header files quickly with open. The -h
option will search and open the header file for a given class. There is an additional -s
option to choose an SDK:
If the search term is ambiguous open
will list all the options.
We’ve all used TextEdit before and though it’s a nice text editor in its own right, almost every one of us prefers to use other software, including the ever-popular Microsoft Word, Apple’s own Pages, and NeoOffice. It’s under appreciated, which is why numerous Mac users are looking for ways to change their default text editors.
How To Open Textedit From Terminal
Although you can always choose to open your text documents by right-clicking and picking the Open With option, there are people who want to save up fingertip stamina by merely double-clicking the selected text files. Fortunately, there are several ways you can change the default text editor on a Mac.
Using Get Info
Let’s say you have a document you’re editing for the long-term and it will stay for days on one of your folders. Given that when you open it, the Mac’s default settings will always lead to it opening on TextEdit. To change this, one of the ways to do this is to resort to change the default text editor by accessing the Get Info menu. Here’s how to do it:
- First, right-click on the document and a drop down menu will appear.
- Select Get Info.
Mac Text Editor Terminal
- After the menu appears there’s a drop down box labeled Open with. Select your preferred text editor from the list. Note that the drop down box may not hold certain word processing programs currently installed on your computer.
You can also use this method to set particular file extensions to open at a program of your choosing.
To do this, simply follow these steps:
- First, right click on the selected file.
- Open the Get Info option.
- Instead of choosing a program from the drop down box, click on Other.
- Pick a program from Finder and once you picked the appropriate one, select it.
- Below the drop down box, a Change All button will appear.
- Click on the said button and a dialogue box – as shown in the picture above – will appear. Click on Continue to open all files with a .docx extension.
You can repeat this for other file types as necessary, particularly on RTF, doc, and txt.
Using the Terminal
Although the above mentioned method is the easiest way you can change your default text editors, you can go take the long way out by using the Mac’s Terminal. Simply go over this Stack Exchange thread to get a clear idea on how to do it.
However, we really don’t recommend using the Terminal for this, given that it’s utterly complicated and you might make a mistake in editing your configuration files. It’s also pretty technical and anyone without proper programming experience would not understand how to do all of it.
Although TextEdit is undoubtedly useful (but only for limited functions), its not a go-to solution for all your word processing tasks. There are several other apps and programs, like MS Word, Open Office, and Sublime Text 2 that can cater to your work-related needs.
To save precious seconds, simply follow the above mentioned procedures and you will find yourself able to open your preferred word processors with a couple of clicks.