Wiki Update: Scripting the Keyboard Maestro editor -- Examples

Hi folks. (First post about editing the wiki as this is about my first edit to same.)

I edited Scripting the Keyboard Maestro editor to add a couple of “building block” snippets of code.

I needed these when building my first macro to actually create macros. (As it happens, it’s invoked from Alfred.)

The two snippets demonstrate tests:

  1. Return true if a named macro group exists. False, otherwise.
  2. Return true if a named macro exists. False, otherwise.

In both cases the name to test for is supplied as a KM variable.

I could probably expand it a little to demonstrate how to pick up properties of either the macro group or the macro.

Thanks for helping out on maintaining the KM Wiki!

Please make sure that whenever you make an edit, that you create a new topic in the Wiki forum category so that we all know about it, and provide others with the opportunity to review.

Your script is good, but could result in misleading results. Whenever you get a KM Variable, you always need to test to make sure it has a value. So, I updated your script with a test and error command:

tell application "Keyboard Maestro Engine"
  set macroGroup to getvariable "macroGroup"
  if (macroGroup = "") then error "[ERROR]" & linefeed & "Invalid Macro Group Name. KM Variable \"" & "macroGroup" & "\" was empty or undefined."
end tell

tell application "Keyboard Maestro" -- Editor
  if exists macro group macroGroup then
    return true
  else
    return false
  end if
end tell

Also, please make sure you have tested and validated the exact script that you post. I just had to remove another script because it would not even compile.

Your description of your changes was good, but it would be helpful (but not required) if you could follow this format in the future. If all Wiki editors will follow the same format, it will make it easier for all of us to quickly read/understand the changes.

  • Topic Title: Wiki Update: <Title of Wiki Page/Section>
  • Topic Body:

Submitted for your review, comment, and/or revision, the following Wiki article has been updated:

### <link to Wiki page/section>

### Primary Changes:

If there are any parts of this article (existing or revised) that you are not sure about, or that you would like confirmation on, please include that you your post here, and link-to, or quote, the specific text of concern/interest.

Thanks again for your help on the wiki.

Thanks @JMichaelTX for your advice. Will follow these guidelines.

I am concerned about the “start a new section” point, but only from the POV of mechanics: It seemed to me the section I edited in had a hardcoded section number. I wouldn’t want to break that.

You're very welcome, and thanks.

I don't know what you are referring to. I reviewed my post, and did not see anything about "start a new section".

My only point about "sections" is that if you edit just a section of a long Wiki article, then it is helpful to specify that section when you post your update notice here.

Unfortunately the KM Wiki does not support auto-numbering of header items. So, although I don't like it and rarely do it, if it seems to add sufficient clarity to the article, I will use hard-coded header number. Best to avoid if we can.

Any other questions?