A Macro to Get OS Information and KM Version?

This will get the macOS "Marketing Name" for your version. It works, but it will also give you a laugh if you read how it works. It puts a couple of files in your home directory. You can fix that if you want. :slight_smile:

I think I have a solution for your other problem, which will also give you a laugh.

Group.kmactions (4.0 KB)

And here, for another laugh, is your answer to your KM version question:

You see, anything is possible with KM. Another creative solution from Sleepy.

Both of these solutions "work" but may not be "the best solution." They illustrate how you can use wild and crazy approaches to solving a problem. And sometimes wild approaches actually work.

In fact, this solution can be fairly easily modified to work with ANY app, not just KM. I'll leave that as an exercise to the reader.

Haha..thanks! This is very creative.
I was thinking of parsing a plist file of an app, but I’m not sure how to do that yet.
Going to bed now. Just put a thought here.

Thanks for saying that. Many of my solutions are "wrong" because I often use a "simple" way to solve problems. Often the "right" solution involves AppleScript, which I'm slowly learning, but too slowly. And AppleScript can be frustrating because I usually find that the variables in an app's dictionary are "readonly" which makes AppleScript useless for half the problems I want it to solve for me. Things like "changing the background colour" of a document are readonly for no apparent reason. I know the blame for that lies with the app developer, but most of the apps I use are from Apple. So Apple is the reason that AppleScript is useless half the time.

I think these "wrong" solutions that I provided above actually have interesting "techniques" that some people could learn from.

My mantra is "if you can see it with your eyes on the screen and do it with your hands using your mouse and keyboard, then you can do it with KM."

P.S. There's a different way you could get the version number (I prefer this way...)


I've found a way to parse the plist file. Here is the macro:

I also prefer this one, as it is 0.1s faster. :smiley:


Ok. Found a way to get the macOS name as well:


MACRO:   macOS and KM Version

DOWNLOAD Macro File:

macOS and KM Version.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.

Hey @martin,

We've been doing this sort of thing for a while now:

Text Expansion: System & Hardware Info

I have text expansions for simple system info, 3 levels of more advanced system info, and various app's version info.

Simple macOS and Keyboard Maestro info can be obtained very swiftly thus:

tell application "Keyboard Maestro Engine" to ¬
   set kmVersion to "Keyboard Maestro " & (its version)
tell (system info) to set macosVersion to "macOS " & (its system version)

set outputStr to macosVersion & " with " & kmVersion

I really like your method of using the macOS software license to get the marketing name of the OS and might just incorporate that into my own scripts.

Here's yet another way:

# Auth: Christopher Stone
# dCre: 2021/08/16 11:09
# dMod: 2021/08/16 16:26
# Appl: Keyboard Maestro Engine
# Task: Create macOS & Keyboard Maestro Version String.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Keyboard_Maestro_Engine, @Version_String
# Vers: 1.0.1
use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions

property macOSXVersionTable : text 2 thru -2 of "
macOS 10.0		Cheetah
macOS 10.1		Puma
macOS 10.2		Jaguar
macOS 10.3		Panther
macOS 10.4		Tiger
macOS 10.5		Leopard
macOS 10.6		Snow Leopard
macOS 10.7		Lion
macOS 10.8		Mountain Lion
macOS 10.9		Mavericks
macOS 10.10		Yosemite
macOS 10.11		El Capitan
macOS 10.12		Sierra
macOS 10.13		High Sierra
macOS 10.14		Mojave
macOS 10.15		Catalina
macOS 11			Big Sur
macOS 12			Monterey

tell application "Keyboard Maestro Engine" to set kmVersion to "Keyboard Maestro " & (its version)
tell (system info) to set macosVersion to "macOS " & (its system version)

set findOSNameStr to my extractUsingPattern:"^(macOS \\d+\\.\\d+)" fromString:macosVersion resultTemplate:"$0"
set findOSNameStr to "(?m-s)^" & (findOSNameStr as text) & "[\\d.]*\\t+(\\w[\\w\\ ]+)$"
set macOSNameStr to item 1 of (my extractUsingPattern:findOSNameStr fromString:macOSXVersionTable resultTemplate:"$1")
set macosVersion to macosVersion & space & "(" & macOSNameStr & ")"

set outputStr to macosVersion & " with " & kmVersion

on extractUsingPattern:thePattern fromString:theString resultTemplate:templateStr
   set theString to current application's NSString's stringWithString:theString
   set theRegEx to current application's NSRegularExpression's regularExpressionWithPattern:thePattern options:0 |error|:(missing value)
   set theFinds to theRegEx's matchesInString:theString options:0 range:{0, theString's |length|()}
   set theResult to current application's NSMutableArray's array()
   repeat with aFind in theFinds
      set foundString to (theRegEx's replacementStringForResult:aFind inString:theString |offset|:0 template:templateStr)
      (theResult's addObject:foundString)
   end repeat
   return theResult as list
end extractUsingPattern:fromString:resultTemplate:



I use Mdls in the Napkin macro to tell if it's running under v8 or v9 of Keyboard Maestro. Which works for any app:

mdls -raw -name kMDItemVersion /Applications/Keyboard\ Maestro.app

1 Like

Hi Chris,
Thanks for the information and the scripts. I tried to search for it, but I guess I used wrong search words.
Your short script works very well.
I'm having issue with the longer one. KME reports this error:

2021-08-16 14:19:00 Execute an AppleScript failed with script error: text-script:1043:1049: execution error: Can’t get item 1 of {}. (-1728). Macro “Trying” cancelled (while executing Execute AppleScript).

Wow. I've not seen mdls before and I don't understand the code.
Just curious: why do you have two versions installed? I did not even know it is possible.

I don't have two versions installed but I did want to make sure Napkin worked on either because the first thing it does is hide the Applications Palette, which wouldn't work on v8.

Hey Mike,

Better to not hard-code the app path. I move all 3rd party apps out of the root of the /Applications folder into appropriate subcategories myself.

kmAppPath=$(mdfind -onlyin /Applications/ 'kMDItemFSName == "Keyboard Maestro.app"c')
echo "$kmAppPath"


1 Like

Test it in Script Debugger, and find where the error is taking place.

I've tweaked the script a bit in the original post.


I'm sorry to report that I'm still having the error:

Turn on show invisible and show spaces.


Comment-out the last 2 lines, and run it again.

I want to see the constructed regular expression.

Sorry. I don't have Script Debugger. I use the Script Editor that came with the OS. Can I do similar debugger stuff here?

Script Debugger has a demo, and after about 30 days it turns into a “Lite” version that is head and shoulders above Apple's Script Editor.app.

If you do anything with AppleScript it's better to use Script Debugger – even in the Lite (free) configuration.


1 Like

Thanks. That's very helpful to know. Someone mentioned Script Debugger on the forum before. When I looked at the price I immediately closed the window and never turned back. I may write AppleScript (or more accurately, revise existing script to suit my needs) less than a handful of times a year. I will not pay that price for doing that.

Not sure what it is.
Is this enough?

I want to see the result of this line:

set findOSNameStr to "(?m-s)^" & (findOSNameStr as text) & "[\\d.]*\\t+(\\w[\\w\\ ]+)$"



Warning: This is gonna get nerdy.

On the Mac, if you go to Safari, and then choose the Safari » About Safari Menu shown here:

Safari About

You will see this:

The first number (“14.1.2” in this case) is the “Version Number” as most people think of it.

The second number (16611. is often referred to as the Build Number, and it’s often not something most people need to or want to know about.

Technically, the first number here is called the CFBundleShortVersionString and the second is called the CFBundleVersion.

You can easily check either using the command-line tool defaults read like so:

defaults read "/Applications/Safari.app/Contents/Info" CFBundleShortVersionString


defaults read "/Applications/Safari.app/Contents/Info" CFBundleVersion

(Both of those are single-line commands, even if they appear “wrapped” here).

You can replace “Safari.app” with just about any other app to get that app’s information. That will work for the vast majority of the apps you will find.

Some apps (including Keyboard Maestro) put the version number in both fields. That’s “less common, but not unusual” if you follow me.

Some apps just use the CFBundleShortVersionString but that is rare. More often you’ll find the information is in both fields.

Some apps just use the CFBundleVersion and have no CFBundleShortVersionString at all, but this is very rare.

Note: Most of Apple's Built-In Apps Aren't Actually in /Applications/ Anymore

Recent versions of macOS include standard apps which appear in /Applications/ but aren't actually in /Applications/. For example, TextEdit.app will appear in /Applications/ but if you try

defaults read "/Applications/TextEdit.app/Contents/Info" CFBundleShortVersionString

You will get an error like this:

The domain/default pair of (“/Applications/TextEdit.app/Contents/Info”, CFBundleShortVersionString) does not exist

If that happens, use /System/Applications/ instead of just /Applications/.

The same is true for applications which appear in /Applications/Utilities/ such as Activity Monitor.app which is actually found at /System/Applications/Utilities/Activity Monitor.app

If you are trying to use one of these apps and are not sure where it is located, the easiest way to find out is to open a Terminal.app window and drag the app to it. That will reveal the actual path that you need to use. Just don't forget to make sure you add /Contents/Info after the .app!