Not always, but often, an Applescript fails (German error message “Keyboard Maestro” hat einen Fehler erhalten: Das Programm läuft nicht.), when the following actions are present in the editor:
Set Variable to Front Browser
Set Safari Field to Text
Interesting: The same setting causes problems in ScriptDebugger when calling up the dictionaries for Keyboard Maestro. The display flickers constantly.
The script terminates as soon as it reaches this statement:
Actions in the editor will potentially be running some level of scripts for displaying their results or condition values.
For example, the Set Safari Field to Text action shows the current value of the field at the bottom of the action when displayed in the editor. To get that requires running an AppleScript.
Most scripts in Keyboard Maestro that refer to web browsers include a clause to check if the browser is running to avoid launching them.
There may be more concise ways of solving this, but try:
tell application "Keyboard Maestro"
set flag to false
repeat until flag
try
set theSelection to (get the selection)
set flag to true
on error
-- do nothing
end try
end repeat
-- do stuff with selected Actions
end tell
The problem seems to be that if the Editor is busy evaluating a Token using AppleScript (so it can preview the result in an Action), the Editor will be unresponsive to incoming AppleScript commands.
The snippet I posted is, quite simply, "No response? Keep trying until successful". Works 100% here.
I need to apologize. I didn't read your script carefully and missed the loop.
Thanks for the tip!
The problem remains: I have a lot of scripts that very often call “tell application ‘Keyboard Maestro’”. Adding your query to every single one of them is very time-consuming.
The solution remains, too -- at least until a "Do not evaluate AS-dependent Tokens" toggle is added to the Editor's preferences. You might be able to get close to that by collapsing any Actions that contain those Tokens and turning off "Evaluate Condition Results" -- no preview of evaluations, no need to query an app, nothing blocking your AS from interacting with the Editor.