How To Use CLI Apps On Mac

Over the last week, I’ve made a few posts covering ways you can get more out of your Mac’s terminal. In one of these posts, I covered some of the best Homebrew CLI apps on Mac.

While I did explain how to install each of these apps, I didn’t explain how to run or use them. And if you’ve never used an app like this before, installing might be all you know how to do.

Today, we’re going to change that. In this post, I’m going to cover how to run CLI apps on Mac, as well as offer a few other tips that should help you get started. After all, CLI apps can be a bit tricky at first, and each is going to work in a slightly different way.

What are CLI apps on Mac?

If you haven’t read any of our previous posts on using the Mac terminal, then CLI apps might sound like a foreign concept. However, these apps are pretty simple once you’re able to wrap your head around them.

In short, a CLI app is an app that runs in your Mac’s terminal rather than through its graphical user interface (GUI). The name “CLI” stands for “Command Line Interface”, with the “command line” being the space in your terminal where you type commands and press return to run them.

Unlike a typical GUI app (like Microsoft Word, Google Chrome, Photoshop, or any other app you use daily), CLI apps are entirely text-based. This means they generally have a steeper learning curve than your typical app. However, they’re also smaller, faster, and capable of things that GUI apps often aren’t.

I recommend checking out some of my previous posts on the Mac terminal to get a feel for what we’re talking about, which I’ve linked throughout this article. It also helps to play around in the terminal a bit so that you understand the basics.

Ok, enough of that! Open your Terminal and let’s start running your CLI apps on Mac.

How to run CLI apps on Mac (most of the time)

To preface, not every CLI app is going to run this way. Some will run similarly, while others are totally unique. But 99% of the time, you’ll use this command to run a CLI app in your Mac terminal:

CLI_app [command]

Ok, let’s break that down.

The first part, CLI_app, is a stand-in for whatever CLI app you’re trying to run. For instance, if I wanted to download a YouTube video using the Homebrew app youtube-dl, I would type youtube-dl into my Mac’s terminal.

Pretty straightforward!

The second part, [command], is a stand-in for whatever command or argument (a.k.a., option) you want the app to execute. For youtube-dl, that command is the URL of the video I want to download.

If I wanted to update youtube-dl, I would instead run the command youtube-dl -U. The command is different, but the format is the same – the name of the CLI app followed by the command for the action I want it to execute.

That first part, where you type the name of the CLI app, is known as “calling” the application. It tells your terminal what app you want to run. The second half, where you type the command, is known as the “argument”. It’s where you tell your terminal what you want to do with the app you just called.

Not all apps are going to need an argument. The tree CLI app, for instance, is its own command. You just type tree into the terminal, hit return, and it performs its action. There’s nothing else to it.

If you try this with an app that requires an argument, like youtube-dl, you should get an error explaining what you did wrong:

As you can see, doing this makes it pretty clear what you’re supposed to do. And most CLI apps on Mac are built this way! If you don’t know the command you want to run, just run the name of the app. Once you know the command and/or arguments, type the name of the app, then the command and/or arguments, then run that all together.

How to get help for CLI apps on Mac

Alright, so let’s say you tried the above and it just didn’t work. Or maybe you only know how to run one command for your CLI app, but you know it has way more commands than that. Here’s another step you can try.

Type the name of the CLI app you’re running into your terminal, followed by any of these commands:

  • help
  • h
  • -help
  • -h
  • ?
  • -?

Your command should look something like CLI_app help. If you try one of these and it doesn’t work, just move down the list until you’ve tried all of them.

Eventually, one of these should bring up a list of information for the CLI app you’re trying to learn about.

The first line after you get one of these commands to work should be one explaining the basic syntax used for this CLI app. For instance, in the screenshot above you can see that the app cask uses the same formula we outlined before: cask [COMMAND] [OPTIONS].

Below that, you’ll see all of the commands available with this app, how to use them, and what they do. I recommend trying this out with all of your CLI apps on Mac, even if you already know how to use them. You’ll probably learn about some new features and options you didn’t know were there.

When help doesn’t work, track down the README

Ok, so you tried all of the help commands above and couldn’t get any help to appear. That means the CLI app you’re using doesn’t have any help commands, or they’re uncommon enough that you probably can’t guess them (thanks a lot, Developer!). The next thing you’re going to want to try is the README.

The README, pronounced and an amalgamation of “read me”, is more or less the user manual for an app. Unlike help, 99.99% of all apps, GUI and CLI, will have a README text file. This is such an industry standard and common best practice that any app without one probably isn’t worth your time. People who write hello-world apps usually include a README.

When you open an app’s README, you’ll find all of the information you could ever want to know about a particular CLI app. For reference, here’s the README for cask.

So, how do you find the README?

By googling! I found the cask README by searching for “homebrew cask readme” on Google. Most of the time, the README will be a markdown file (.md) on GitHub.

If you installed the app using Homebrew, you can usually find information on the app on Homebrew Formulae. Just search for the app in the search bar and follow the links it provides you with. These will either link to the app’s GitHub page or website, where you should be able to find the information you’re looking for.

How to run a CLI app file on your Mac

So far, we’ve covered how to run CLI apps on Mac that have been installed. Sometimes, though, your app is just a file on your computer. This is generally the case when you’re building your own app or you’ve downloaded a basic CLI app from the internet that doesn’t install on your device.

Fortunately, running apps like this is pretty simple. You just need to know which file of the app is the parent (i.e., all of the other files run underneath the parent file) and what language that parent file is in. For example, let’s say you have the following files:

  • my_CLI_app.py
  • images.py
  • library.json
  • error_resolution.py

Though these are separate files, they all run together to make a single app. From the titles, however, it’s pretty clear that the my_CLI_app.py is the parent app – if you run it, everything else will run in conjunction with it as needed. We can also tell by looking at the extension to this app that it’s written in the Python programming language.

With these things in mind, we know which file to run and that we need Python to run it. So first things first, you would need to make sure you have Python installed on your Mac. To do this, run python -V in your terminal (other programming languages have a similar command; just google “which version of [programming language] do I have”).

If you have that language installed on your Mac, navigate to the folder where the app file is located (tutorial on navigating with the terminal here). Then, use the following command in the terminal:

python my_CLI_app.py

This will run the app in your Mac terminal.

And that’s it!

Open GUI apps from the terminal on Mac

Admittedly, that last section was a bit complicated. Let’s close out with something much simpler! Opening GUI apps from your Mac terminal.

When we’re talking about “opening GUI apps from your terminal”, it’s just a complicated way to say that we’re going to run a standard app on your Mac from the terminal. This could be the App Store, Finder, Safari, Photoshop, Microsoft Word, etc.

You can use this method to run any GUI apps on your Mac from the terminal. There’s not necessarily a practical reason to do this, but it’s fun nonetheless!

To do this, use the following command:

open -a "App Store"

Or this one:

open -a Pages

Or:

open -a Calculator

Or anything else! Unlike the previous section, you can do this from anywhere on your Mac; you don’t have to navigate to the folder that contains that app to run it. And while I only listed Mac apps in the above commands, you can do it with any app on your Mac. I just chose these since all Mac users have them.

And that’s it!

Explore your Mac with CLI apps

I’ve said it before: Few things are as rewarding as taking a peek under the hood of your computer and learning how to tinker with it. CLI apps on Mac are a great way to do this. I hope you learned something from this post and have greater confidence when experimenting with CLI apps in the future! Be sure to check out the rest of the AppleToolBox blog for more tips and tricks on working with the terminal, as well as all things Apple.

Leave a Reply

Discover more from Ultimatepocket

Subscribe now to keep reading and get access to the full archive.

Continue reading