cmc/cleberg.net

My personal web garden & blog.

clone: git clone https://gitbay.org/cmc/cleberg.net.git

main: content/blog/2026-06-01-macos-motd.org · raw

  1#+date: [2026-06-01 Mon 12:02:02]
  2#+title: Bring MOTD to macOS
  3#+description: Learn how to quickly and easily create a custom message of the day for macOS systems.
  4#+slug: macos-motd
  5#+filetags: :mac:
  6
  7* Messages of the Day (=motd=)
  8
  9A [[https://en.wikipedia.org/wiki/Message_of_the_day][message of the day]] is, in computer terms, a welcome message that provides
 10information and may help users logging onto the system. This is useful for
 11numerous reasons, depending on the system, such as community announcements,
 12compliance requirements, contextual information for that system, etc.
 13
 14In this post, I'll be walking through a simple way to generate a message of the
 15day for macOS. You can see the end result in this screenshot below:
 16
 17#+caption: macOS message of the day
 18#+attr_html: :alt Terminal output of motd.sh showing the system and user information upon launching a new shell.
 19[[https://img.cleberg.net/blog/20260601-macos-motd/macos-motd.webp]]
 20
 21For an example of a system-provided =motd=, here's the =motd= on my Ubuntu server
 22showing the server's default information and any relevant add-ons, such as the
 23LAN cockpit URL:
 24
 25#+caption: Ubuntu message of the day
 26#+attr_html: :alt Terminal output of Ubuntu's default server message of the day, showing system information.
 27[[https://img.cleberg.net/blog/20260601-macos-motd/ubuntu-motd.webp]]
 28
 29* Create the Message
 30
 31First, we need to create the message. In this example, I've created a custom
 32shell script below that uses terminal formatting to generate a structured
 33output. This script checks for:
 34
 35- username
 36- hostname
 37- profile management
 38- WiFi SSID
 39- IP address
 40- Mullvad status
 41- battery status
 42- uptime
 43
 44To do this, create a script in your user directory:
 45
 46#+begin_src shell
 47nano ~/.motd.sh
 48#+end_src
 49
 50Then paste the content below and modify as needed:
 51
 52#+begin_src shell
 53BOLD='\033[1m'
 54DIM='\033[2m'
 55RESET='\033[0m'
 56
 57HOST=$(scutil --get ComputerName 2>/dev/null || hostname)
 58
 59IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null)
 60IP=${IP:-unavailable}
 61
 62SSID=$(networksetup -getairportnetwork en0 2>/dev/null | sed 's/^Current Wi-Fi Network: //')
 63case "$SSID" in
 64  ""|"You are not associated with an AirPort network.")
 65    SSID="unavailable"
 66    ;;
 67esac
 68
 69BATTERY=$(pmset -g batt 2>/dev/null | awk -F'; *' '
 70  NR==2 {
 71    gsub(/^ +| +$/, "", $2)
 72    gsub(/^ +| +$/, "", $3)
 73    sub(/ present: true$/, "", $3)
 74    print $2 ", " $3
 75  }
 76')
 77BATTERY=${BATTERY:-unavailable}
 78
 79UPTIME=$(uptime | sed 's/^.*up //; s/, [0-9]* user.*//; s/, load averages.*//')
 80UPTIME=${UPTIME:-unavailable}
 81
 82if profiles status -type enrollment 2>/dev/null | grep -qi "MDM enrollment: Yes"; then
 83  MANAGED="yes"
 84else
 85  MANAGED="no"
 86fi
 87
 88VPN="unavailable"
 89
 90if command -v mullvad >/dev/null 2>&1; then
 91  STATUS=$(mullvad status 2>/dev/null)
 92  VPN=$(printf '%s\n' "$STATUS" | head -1)
 93  VPN=${VPN:-unavailable}
 94fi
 95
 96printf "\n"
 97printf "  ${DIM}%-14s${RESET}${BOLD}%s${RESET} ${DIM}%s${RESET}\n" "$USER" "$(uname -sr)"
 98printf "  ${DIM}%-14s${RESET}%s\n" "host" "$HOST"
 99printf "  ${DIM}%-14s${RESET}%s\n" "managed" "$MANAGED"
100printf "  ${DIM}%-14s${RESET}%s\n" "wifi" "$SSID"
101printf "  ${DIM}%-14s${RESET}%s\n" "ip" "$IP"
102printf "  ${DIM}%-14s${RESET}%s\n" "mullvad" "$VPN"
103printf "  ${DIM}%-14s${RESET}%s\n" "battery" "$BATTERY"
104printf "  ${DIM}%-14s${RESET}%s\n" "uptime" "$UPTIME"
105printf "\n"
106#+end_src
107
108Finally, modify the script file to enable execution:
109
110#+begin_src sh
111chmod +x ~/.motd.sh
112#+end_src
113
114* Load the Message
115
116At this point, the script is ready. We simply need to tell macOS to execute it
117whenever the user launches a new shell.
118
119To do this, open the =.zprofile= file and add a line referencing the script:
120
121#+begin_src shell
122nano ~/.zprofile
123#+end_src
124
125#+begin_src
126# Display Message of the Day (MOTD)
127./motd.sh
128#+end_src
129
130All done! This method is easily customizable and allows for use of dotfile
131management systems, such as stow, since the files live in the user's home
132directory.