Request: Availability of Text Tokens to Applescript

I've been expanding my AppleScript activities and have run into a problem that I hope can be solved.

In the following example AppleScript taken from a test KM macro

tell application "Keyboard Maestro Engine"
   set v1 to process tokens "%SafariTitle%"
   set v2 to process tokens "%ExecutingMacro%"
end tell
display dialog v1 with title "Testing SafariTitle"
display dialog v2 with title "Testing ExecutingMacro"

The first dialog shows the title of the current page in Safari fine but the second dialog displays nothing for v2. In other words, the KM text token %ExecutingMacro% is not being picked up.

This has been mentioned in a previous post from 2016 (AppleScript process tokens with some Macro Information tokens) as being a consequence of how AppleScripts work in KM.

As I'm developing a plugin action, I need the plugin's AppleScript code to obtain the value of %ExecutingMacro%, but I do not want to have to put that value in a KM variable first as stated in the above 2016 discussion. The reason is that having to use a KM variable would be external and additional to the plugin and would require the named variable and the code in the plugin to be coordinated and therefore subject to error.

My request to @peternlewis is this: can text tokens such as %ExecutingMacro% be made to play nice with AppleScript in KM in a future update? Or is there some other AppleScript magic that can be used to obtain such text tokens' values?

1 Like

That would require an instance parameter like setvariable/getvariable have. I will add it to the todo list.


Thanks. I dread to think what your to do list is like :astonished:


Hi @peternlewis - Homer Simpson here - DOH!

It just dawned on me as my AppleScript and KM Plug in experiments continue that I can easily access the values of otherwise inaccessible things by passing them to my plug in through the use of Hidden parameters! Like this:

KM 1 2020-11-08_17-24-26

In my plugin I can now access the value of %ExecutingMacro% through a line of AppleScript like this:

set theMacro to system attribute "KMPARAM_Calling_Macro"

which results in the variable theMacro being set to the value in question and eliminates the need for an intermediary KM variable to be set outside the plug in.

I thought it best to put this onto the forum for future reference.

Once again I am amazed by the capabilities built into KM. It makes me feel like a new user all over again.


I have added the instance parameter to the process tokens and calculate AppleScript commands in the engine for the next major version.


Thank you Peter @peternlewis. Now I can add something to my todo list for version 2 of a couple of my plug ins!

1 Like