How do I make the custom lock message display my ComputerName automatically

Hi


This article How to set a lock message on the login window of your Mac - Apple Support describes how to put a fixed message on the login screen. I want to display the current computer name there without having to go and type it in on each of my 40-odd machines, and so it will update by itself if I change a computers name from ARD.


I found the LoginwindowText in /Library/Preferences/com.apple.loginwindow.plist but when I changed it to HostName it (of course, but I had to try it anyway!) it just printed "HostName"


What is the correct trick here?

Mac mini, OS X Server

Posted on Jun 1, 2017 5:12 PM

Reply
5 replies

Jun 2, 2017 12:25 AM in response to auntyjack

Ha! I have it. This does the trick . . .


#!/bin/bash

# DisplayName. Displays the ComputerName at the Login screen


if [ $(whoami) != 'root' ]; then

echo "Must be root to run $0"

exit 1;

fi


computer_name=`/usr/libexec/PlistBuddy -c 'Print :System:System:ComputerName' /Library/Preferences/SystemConfiguration/preferences.plist`

defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText $computer_name

exit 0

Jun 1, 2017 9:09 PM in response to auntyjack

Here is the challenge that you will face. You will need sudo privileges to add, or change content in the /Library/Preferences plist files because they are owned by root and in group wheel. Once the content is in there, you cannot remove it via sudo, or even root itself using Xcode.


I can write to the com.apple.loginwindow.plist file using sudo PlistBuddy, so adding, or overwriting the LoginwindowText property is doable. This does require disabling System Integrity Protection in Recovery mode on each recent host that has SIP enabled.


This may be a show-stopper for remote access via ARD. I would never recommend permanent disabling of System Integrity Protection.


I have a Bash script (must be run as sudo) that checks to see if the LoginwindowText property is in the loginwindow.plist file. If it is, it compares that string value to the current hostname, and writes the current hostname if they don't match.


If the LoginwindowText property is not (default) in the Loginwindow.plist file, it will add the property and its current hostname string.


Interested, despite the System obstacles above?

Jun 2, 2017 4:38 AM in response to John Galt

The LoginwindowText key does not exist by default. It must be added. If you don't disable System Integrity Protection, the PlistBuddy command executes with a normal return that would indicate success, but the key and its value are not added. It would be wise to test this by following with a grep -ac LoginwindowText foo.plist to ensure that you get a count (1) for a confirmation of a successful addition.


The command sequences:

sudo /usr/libexec/PlistBuddy -c "add LoginwindowText string $(scutil --get ComputerName)" /Library/Preferences/com.apple.loginwindow.plist

/usr/libexec/PlistBuddy -c "print LoginwindowText" /Library/Preferences/com.apple.loginwindow.plist

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I make the custom lock message display my ComputerName automatically

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.