I was talking with @_jims about his 𝗌.𝘂⇾PlatformVersions, v2.0 subroutine, and how Apple makes it hard to get the macOS code name (Sonoma, Ventura, etc.) from any non-GUI source.
It being a Saturday morning, one thing led to another and I wondered what might be the quickest way to get that tidbit, amongst the methods I either knew about or could figure out. The end result? This little macro that contains five different ways to get the name of the installed macOS version:
Download Macro(s): macosversion.kmmacros (27 KB)
Macro notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System information
- macOS 14.4.1
- Keyboard Maestro v11.0.2
If you're going to use this to test or play around with, you'll either need to disable the purple calls to a missing macro, or install myMultiTimer—that's what does the timing.
Also, enable just one method at a time (the green boxes), as they all use the same variable name. I've found that if you're testing a bunch of routines back to back in one macro the timing can change based on the order things run, so I always run them one at a time.
The five methods I tested were:
- a shell
case
statement that looks up the value from a list of releases - a shell
grep
of a variable containing the list of releases - a KM regex search of a variable containing a list of releases
- Jim's original KM Case action
- a shell
grep
(found here) of the license agreement file, which doesn't rely on a lookup but will break if Apple changes the layout of the license agreement
And here's how things came out...
Yes, Jim's original multi-case Case statement is the quickest. I was very surprised to see that the KM Case statement is quicker than any of the shell alternatives. It's a close second with the regex, which is probably how I'd implement it if I were using a list lookup—only because I'm lazy and like editing a simple list more than I like editing a long Case statement.
In my own use, though, I'm using the non-lookup solution, because I'm even lazier than lazy, and this way, I won't have to update my macros unless/until Apple changes their license agreement text :).
I was wondering if there might still be a quicker way out there. You can get the name via AppleScript in System Settings, but there's no way that's quicker. Maybe JXA, but I know almost nothing of that. In any event, even the slowest of slow methods was under a tenth of a second, which is why this was just a Saturday morning diversion :).
-rob.