I can't see it in KM, I am sure I could do it in apple script but it seems a sensible thing to include within KM surely.
AFAIK, this is NOT possible in native KM Actions.
Note that your AppleScript uses the "Keyboard Maestro" app, where as all macros use only the "Keyboard Maestro Engine".