Hey everyone, I’m managing a bunch of macOS devices (Monterey), and I’ve hit a bit of a snag. Most of the devices only show the time in hours and minutes—no seconds. On top of that, we use a 12-hour clock format, but some devices don’t display AM/PM. It’s super exhausting to manually go into each system and fix this. Does anyone have any scripts or methods to tackle these issues? Would really appreciate some help here!
Modify time settingsSolved
Tags
Replies (6)
Hey @luuk, I think a simple defaults write command should do the trick:
1 |
defaults write com.apple.menuextra.clock DateFormat –string ‘hh:mm:ss a’ |
Oh yes, yes, the command works fine when run directly in the terminal, but when I push it using Hexnode’s execute custom script action, it fails. Can anyone help me with this?
Oh no worries, I ran into this issue a while back. When executing defaults write commands via Hexnode’s execute custom script action, the script runs in a root level rather than under the logged-in user. Since defaults modifies user-specific preferences, it may not take effect unless explicitly executed in the user’s session. Using launchctl asuser ensures that the command runs within the correct user context, resolving this issue
Here’s a modified script that should work:
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write com.apple.menuextra.clock DateFormat -string 'hh:mm:ss a' |
Hey there, I was wondering if there’s a script to change the time format to 24-hour and make the time uniform across every device in our organization. I tried some scripts, but they didn’t work.
Hello @ryker,
You could use a similar command to achieve this:
1 |
defaults write com.apple.menuextra.clock DateFormat -string 'HH:mm:ss' |
And if you need to revert back to the 12-hour format, then:
1 |
defaults write com.apple.menuextra.clock DateFormat -string 'hh:mm:ss' |
I’m not sure about the latest versions, but it worked for Monterey. Let me know if it helps!
Thank you! We mostly use monterey or earlier versions, and now every device is updated perfectly. Really appreciate the help!