Skip to main content

We are trying to change the MacOS Date & Time setting "24-hour time" on 15.2 via a script.


There is nothing recent / working anywhere on the web. Is it impossible?

Have you tried using Composer to capture any new or modified files when making the clock change?


Use the below command to change it to 24hrs. Make sure you're running this command as a user if you're running it via the JAMF Policy


 


defaults write com.apple.menuextra.clock DateFormat -string 'EEE MMM d H🇲🇲ss'

 plist located at the user library  ~/Library/Preferences/com.apple.menuextra.clock 


Use the below command to change it to 24hrs. Make sure you're running this command as a user if you're running it via the JAMF Policy


 


defaults write com.apple.menuextra.clock DateFormat -string 'EEE MMM d H🇲🇲ss'

 plist located at the user library  ~/Library/Preferences/com.apple.menuextra.clock 


You might also need to logout/restart for the changes to reflect


 


Use the below command to change it to 24hrs. Make sure you're running this command as a user if you're running it via the JAMF Policy


 


defaults write com.apple.menuextra.clock DateFormat -string 'EEE MMM d H🇲🇲ss'

 plist located at the user library  ~/Library/Preferences/com.apple.menuextra.clock 


We are on 15.2 and I don't think this plist / command works anymore. I say that because we just toggled 24 hour time on, it is definitely on, and the plist is not changing. Even if we do change the plist, the actual 24-hr display is not affected. Even after a reboot. This is what it looks like even with 24h time showing.


 


<?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>DateFormat</key>
<string>EEE MMM d hh:mm</string>
<key>Show24Hour</key>
<string>0</string>
<key>ShowAMPM</key>
<true/>
<key>ShowDate</key>
<integer>0</integer>
<key>ShowDayOfWeek</key>
<true/>
<key>ShowSeconds</key>
<true/>
</dict>
</plist>


Using Composer I found a reference to 24 hour time in ~/Library/Preferences/.GlobalPreferences.plist. When enabled AppleICUForce24HourTime exists as a boolean in the file, when disabled the key does not exist. I've tested this and it works but you'll need to log out/in. You could probably kill a process like Finder or something but you'll need to trial and error to find it.


to enable


 


defaults write /Users/<username>/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime -bool TRUE

 


then log out/in


to disable


 


defaults delete /Users/<username>/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime

 


then log out/in


Test and let me know.


Shannon


Using Composer I found a reference to 24 hour time in ~/Library/Preferences/.GlobalPreferences.plist. When enabled AppleICUForce24HourTime exists as a boolean in the file, when disabled the key does not exist. I've tested this and it works but you'll need to log out/in. You could probably kill a process like Finder or something but you'll need to trial and error to find it.


to enable


 


defaults write /Users/<username>/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime -bool TRUE

 


then log out/in


to disable


 


defaults delete /Users/<username>/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime

 


then log out/in


Test and let me know.


Shannon


This works! Oddly, if you disable 24h then run the command and logout or reboot it shows 24h time but the slider is off in Settings. Also, one more thing - I packaged up this script and put it in a user folder, but how do I have it run? Is there a way to do this in the package itself?


This works! Oddly, if you disable 24h then run the command and logout or reboot it shows 24h time but the slider is off in Settings. Also, one more thing - I packaged up this script and put it in a user folder, but how do I have it run? Is there a way to do this in the package itself?


Glad to hear you got it to work.


You should be able to just run a script on a policy. You can also create a payload less package. Take a look at https://derflounder.wordpress.com/2014/06/01/understanding-payload-free-packages/ in the section titled "Using Scripts with Flat Packages". It then goes to his GitHub repo.


Glad to hear you got it to work.


You should be able to just run a script on a policy. You can also create a payload less package. Take a look at https://derflounder.wordpress.com/2014/06/01/understanding-payload-free-packages/ in the section titled "Using Scripts with Flat Packages". It then goes to his GitHub repo.


Great utility, but I can't seem to get to work. I select the script, create the pkg, and the pkg always says it failed, maybe due to the tilde?


defaults write ~/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime -bool TRUE

exit 0

Great utility, but I can't seem to get to work. I select the script, create the pkg, and the pkg always says it failed, maybe due to the tilde?


defaults write ~/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime -bool TRUE

exit 0

I'm not familiar with the utility as I am comfortable building packages, perhaps it might be worth reaching out on the repo page.


Having said that though, you're probably attempting to set the key for the root user as packages are installed with root privileges, "~" will mean "/var/root". If your intention is to change the clock for the logged on user then you'll need to work out the currently logged on user and change "~" to the full path. There are multiple ways to do that, I'm a fan of 


CurrentlyLoggedInUser=$(/usr/bin/stat -f %Su /dev/console)

 then you can use the variable CurrentlyLoggedInUser, something like 


defaults write /Users/"${CurrentlyLoggedInUser}"/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime -bool TRUE

Don't forget to fix up the permissions on the file.


Hope this helps.


Shannon


Ok, so the answer is as follows:


1) Use https://derflounder.wordpress.com/2014/06/01/understanding-payload-free-packages/ to create an installation package that runs at user-level


2) Install MacAdmins python https://github.com/macadmins/python 


3) Use this script: (NOTE We used this approach: https://macmule.com/2014/11/19/how-to-get-the-currently-logged-in-user-in-a-more-apple-approved-way/)


#!/bin/bash

#!/Library/ManagedFrameworks/Python/Python3.framework/Versions/Current/bin/python3

loggedInUser=$(/Library/ManagedFrameworks/Python/Python3.framework/Versions/Current/bin/python3 -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\\n");')

defaults write /Users/"$loggedInUser"/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime -bool TRUE

exit 0

 


Reply