How to Build a macOS Menu Bar Disk Analyzer Utility App with SwiftUI and Command Line Tools

Karin Prater

Summary:

This video tutorial demonstrates how to build a macOS menu bar utility app using SwiftUI and system command-line tools.

Disk Analyzer App in macOS menu bar showing disk space overview and donut chart.
Disk Analyzer App in macOS menu bar showing disk space overview and donut chart. [ 00:00:25 ]

  • It begins by introducing command-line tools like df (disk free) and du (disk usage) to fetch disk space data, explaining their differences and flags (-H for human-readable, -k for kilobyte).
  • The core functionality involves fetching raw disk data using the df -k command and parsing it line by line into a Swift DiskInfo model.
  • The tutorial then focuses on transforming this raw data into a FormattedDiskInfo model suitable for UI display, including calculations for percentages and formatting for human readability using ByteCountFormatter.
  • The SwiftUI user interface is built, featuring a list of disk usage categories with custom progress bars and a pie chart to visually represent disk allocation.
  • Finally, the application is integrated into the macOS menu bar using MenuBarExtra, showing how to set its style to appear as a window rather than a list of buttons.

Introduction to Menu Bar Utility Apps [0:00]

Understanding Command Line Tools [0:41]

Building the macOS Disk Analyzer App [5:32]

Creating the View Model and Parsing Data [6:32]

Displaying Data in SwiftUI [22:22]

Integrating the App into the Menu Bar [34:01]