Advanced macOS Command-Line Tools

2023/06/27
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

macOS is fortunate to have access to the huge arsenal of standard Unix tools. There are also a good number of macOS-specific command-line utilities that provide unique macOS functionality. To view the full documentation for any of these commands, run man <command>.

One of these tools is caffeinate, which can be used to set Mac sleep behavior. Running caffeinate with no flags or arguments prevents your Mac from going to sleep as long as the command continues to run. Adding the -u -t <seconds> flags also prevents sleep for the specified number of seconds. Specifying an existing process with -w <pid> automatically exits the caffeinate command once the specified process exits. Passing a command with caffeinate <command> starts the given command in a new process and will prevent sleep until that process exits.

Another useful tool is textutil, which can convert files to and from Microsoft Word, plain text, rich text, and HTML formats. For example, textutil -convert html journal.doc converts journal.doc into journal.html. The possible values for -convert are: txt, html, rtf, rtfd, doc, docx.

Finally, mdfind can be used to search with Spotlight. mdfind <query> performs a keyword-based Spotlight search with the given query. mdfind kMDItemAppStoreHasReceipt=1 finds all apps installed from the Mac App Store. mdfind -name <name> searches for all files matching the given name.

These command-line tools can save developers time and effort by providing quick access to unique macOS functionality.