A Macro to Get OS Information and KM Version?

After being around the forum for some time and asked and answered quite a few questions, I feel that there might be a need to provide the MacOS information as well as the KM version information.

A macro to do that will be great.
I've found an AS code to print the macOS version:

return system version of (system info)

It does not give the OS name though. I would like to include the OS name as well (e.g., Big Sur).

I don't know how to get the KM version information.

Also, is there a general way to get version information for any specified app?


1 Like

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\\ ]+)$"