Terminal – Display Message on Login

bashlaunchdplistterminal

I want to display something like ### this is a test ### when a new Terminal window is open (and ideally, in a way that can be disabled easily). On Linux this was straightforward; you'd create a script in /etc/profile.d/ which would be responsible for echo-ing the message when a new Terminal session is opened.

I've been playing around with launchd to try to get this to work but to no avail. I've created an agent in /Library/LaunchAgents/org.test.greeting.plist with the following code (where the greeting.sh file is responsible for doing the echo) hoping to get some output when the user logs in.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.test.greeting</string>
    
    <key>ProgramArguments</key>
    <array>
        <string>/Users/test/greeting.sh</string>
    </array>
    <key>RunAtLoad</key><true/>
</dict>
</plist>

This hasn't worked, as the message is lost to the ether. However, I do know that the agent is running successfully. I know it is possible to redirect the output to a file using StandardErrorPath and StandardOutPath but those are not useful to me.

Does anyone know how to get this working with launchd, or maybe have another way of doing this?

Best Answer

I like the message of the day for this. As tradition dictates...

me@Mac ~ % echo "Welcome to the University of East Westia" > /tmp/motd
me@Mac ~ % sudo mv /tmp/motd /etc

Note: /etc/motd is only displayed in a login shell, which is typical of Terminal.app on macOS. If you typically run non-login shells, you should handle display of /etc/motd in your shell dot files.