Dynamic MOTD (Message of the Day) for macOS.
If you're not familiar with MOTD, or what 'update-motd' does on some *nix distributions, you should ask your friendly neighborhood LLM about it.
However, if you're feeling adventerous, I'll give you the TLDR here:
MOTD is a dynamically generated (usually, but can be static too) file that is sent to your terminal whenever you initiate an SSH or other login session. MOTD is awesome, and anyone who tells you otherwise simply doesn't know how to operate a computer.
This mechanism is what provides the information that you see when you log in to a remote server, for example, and are shown details about the host name, uptime, OS, whether package updates are available, etc.
On macOS, there is no dynamic MOTD generation mechanism that I'm aware of (if you are aware of one, please let me know!). This implementation is simple: the primary zsh script (mac-motd) generates the necessary
files and directories in preparation for use upon installation.
A cron-like task is enabled which periodically enumerates the zsh scripts in the MOTD update script folder (/etc/update-motd.d), and appends their output to the MOTD file, causing it
to be rejuvenated.
Typically these scripts are given names like 10-header-hello. This is because when the scripts are executed, they are
done so in a descending alphanumeric sort order; a script that starts with '1' is going
to run before one that starts with '2', and so on. This ensures that the MOTD file always has the content in the correct order.
All of the output generated by these scripts (to stdout) is piped into the MOTD file,
so all you have to do is generate useful output. That, I leave up to you, but if you use the default sample setup, which is implemented in
./update-motd.d/20-info-sample.zsh, you'll get the system uptime and the current date/time (or at least, the last time the MOTD was generated).
After many months of being neglected, I believe we have an MVP (Minimum Viable Product) in version 1.1.0. It works for me, at least, on macOS Tahoe 26.2 (25C56).
Some simple properties in the Launch Daemon plist were causing it to be ignored by the OS, and I became under the impression that what would be required to move forward is a Privileged Helper. I have since learned that is not the case, which is good, because I wasn't about to take the time to write and digitally sign an executable that had one purpose: run a zsh script.
- Clone the repo/download the source code zip/tarball
- As root/using
sudo, execute./mac-motd -ito install macMOTD on your system (if you want to override the MOTD regeneration frequency/the log file path, see the output of-hand use the appropriate options alongside-i). Installation performs the following:
mac-motdwill be installed to a system bin directory where it can be found globally.- All of the zsh scripts in
./update-motd.dand its descendant directories will be copied to/etc/update-motd.d, and set to be executable by root. - A Launch Daemon plist is written to
/Library/LaunchDaemons, which causes the now globalmac-motdto be executed with the-g(generate) option every n seconds (default is 600 = 10 mins). - When that command is executed, it will enumerate the scripts that are executable and have a
.zshextension in/etc/update-motd.d, execute them in ascending alphanumeric sort order, and append their output to the MOTD that will appear in users' terminals.
See the output from mac-motd -h under -u, --uninstall. You may choose to:
- Leave all of the scripts in
/etc/update-motd.dalone - Rename them so they won't be executed, but still exist on disk
- Nuke them irreversibly
Regardless of which of these you choose, the Launch Daemon, global mac-motd script, and all other files generated/installed during installation and operation will be deleted.
There are some useful utility functions in ./update-motd.d/motd-helpers/motd-base.zsh which are there to allow for easy printing of colored/stylized text in your MOTD. Additionally, there is an entire WIP of system utility functions that do things like obtain performance metrics, identify OS version, etc. in ./update-motd.d/motd-helpers/scratchpad.zsh. Only some of these work fully, and I don't remember which, so godspeed. One day I will sit down and finish it. One day.