How to display the date on the OS X lock screen

Today, my wife asked if I could have the lock screen on my OS X workstation at home display the date, so she could easily see the date, without logging in. This is the screen that is shown when you are logged in, but the screensaver is locked. By default, it displays the logged-in user’s desktop background, the time, battery status, and a login box. This should be a simple problem to solve, right?

It turns out, I’m not the only one with this question. The accepted answer on that post suggested using a 3rd-party application to dynamically change the wallpaper, to include the time and date. While that might work, it seemed like overkill to solve such a simple problem, and I’m worried about the performance impact this application might have (though it is probably minimal).

The other suggestion on that page seemed to be geared toward displaying the time in 24-hour format, rather than including the date, and in any case, it didn’t work for me (on Mac OS 10.9.5).

In my research, though, I discovered that you can include a static text message on the lock screen. This can be configured using the UI by going to System PreferencesSecurity & PrivacyShow a message when the screen is locked.. It turns out, you can also set this message using the terminal:

sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Hello World!"

This is great, but this message is static. There is no magical code you can include in the message to display the date.

So, the solution I came up with is to create a cron task to update the message every day. This is a bit of a hack, but it doesn’t involve installing any 3rd-party code, and it has no performance implication.

To get the current date as a string, I ran the following command:

$ date '+%B %d, %Y'
February 08, 2015

Because the command to update the lock screen text needs to be run with sudo, you need to add an entry in root‘s crontab:

$ sudo crontab -e

I wanted to update the message every day at midnight, so the full crontab entry I used was:

0 0 * * * defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "The date is `date '+%B %d, %Y'`"

Hope someone else finds that useful!

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>