Opening One File
If you just want to open one file with the default application associated with that file type on your Mac, then you can use the following command to do your bidding:
open file.txt
Replace “file.txt” with the directory path and file that you wish to open. When you press enter, a Mac app will launch, opening the file you’ve specified.
Opening Multiple Files
Let’s say you found multiple files in a search of your drive, and you now want to open those with native Mac applications. Well, this is easier than you think. To do this, use the following command:
open myFile1 myFile2 myFile3
Replace myFile1, myFile2, and myFile3 with the paths and file names of the files that you wish to open. You can keep on adding file names as you like, ensuring there is a single space in between each of the filenames that you wish to open.
Choosing the Application
You may not always want the default application on your Mac to handle the opening of a particular file. In this instance, you can use the following flag on the open command to choose the app you wish to open the file with:
Get the best Black Friday deals direct to your inbox, plus news, reviews, and more.
Sign up to be the first to know about unmissable Black Friday deals on top tech, plus get all your favorite TechRadar content.
open -a appName fileName
Replace appName with the name of the app you wish to open the file with, and replace fileName with the path and name of the file you wish to open. For example, if we had a file called “myFile.rtf” that we wanted to open with Pages, we could type the following command:
open -a pages myFile.rtf
When you press the enter key, the Pages application will launch, opening the file that you specified. This will work with any application installed on your Mac located in your Applications folder.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author on Twitter.
Need extra storage for your new M4 Mac mini but don't want to pay Apple's steep upgrade prices? This unique external SSD might be the game-changer you’re looking for
Friends and colleagues call me 'the Apple Hater', but my only Cyber Monday purchase this year was a certain excellent little Apple product...