Use Mac Terminal Command ‘say’ Smartly as a Programmer

Capt. Michael
3 min readAug 6, 2023

Running commands in the terminal is an indispensable part of a programmer’s work, and some of them really consume time.

For programmers who work on Mac or Linux, we have && and ; to concat different commands within one line and run them one by one automatically. For instance:

rm -rf dist; yarn build && ll dist

The difference between && and ; goes, if the command before && runs failed, then the command after && won’t run. But ; will never stop the process. So, about the above sample, no matter whether rm -rf dist runs succeed or not, yarn build will always start, but ll dist will run only if yarn build succeeds. By the way, the spaces at the beginning or end of both && and ; are not necessary, you can just remove them and make the command line look more compact if you like.

OK, they’re just some preconditions, let’s cut to the chase.

"scripts": {
...
"deploy": "rm -rf dist&&rm -rf output&&yarn generate&&gcloud storage cp output/* gs://static_website_name --recursive&&rm -rf dist&&rm -rf output",
}

I applied a script named deploy into the package.json file of a web project, its purpose is to build and deploy the static site generation to Google Cloud Storage, and if everything goes well, it will finally clean all built stuff. And after this, usually, I’d like to push my Git commit as well. Then, the typical command line I run is like the following:

clear; yarn deploy && git add . && git commit -m 'feat: feature name' && git push

There’re two tasks which take lots of time, the first one is, of course, yarn deploy and the second one is git push as my network is not very friendly to GitHub. If I don’t want to check the terminal panel for the result time and time again, say is a good choice for me.

clear; yarn deploy && say deployed && git add . && git commit -m 'feat: feature name' && git push && say pushed

Let’s add some humanity to the terminal, using say command after each time consumed task to make some vocal feedback, then you can do something else while the whole command line is running and there is no need to keep your eyes on watching.

Sometimes, if the result of a command is human readable, and it’s better to read it loud instead of some words like “done”, “finished” or something like, then you can output it into a file, and make the say to read it:

dig +short google.com > ~/Desktop/ip.txt && say -f ~/Desktop/ip.txt

The aboving commands aim to get the IP of the target domain name and output it to a text file, and then read it. Once you hear the voice of reading the IP address, that means it’s finished.

The command say has plenty of other parameters for different usages, you can check HERE for more details. And hope it can make you more productive!

--

--

Capt. Michael

A full stack developer, freelancer & restless slave of probability.