User Tools

Site Tools


action:Execute_a_JavaScript_For_Automation

**This is an old revision of the document!**

The Execute a JavaScript For Automation action executes a specified JavaScript, either from a file or text.

The results of the script can be:

  • Ignored.
  • Displayed in a floating window.
  • Displayed briefly in a Notification.
  • Typed in to the current selection.
  • Pasted in to the current selection.
  • Saved to a variable.
  • Saved to the system or a Named Clipboard.
  • Asynchronously ignored — the action runs while the macro continues on.

JavaScript For Automation scripts are executed in the background via osascript. This means they are not allowed to do user interaction. You can work around this by asking an application like System Events to do the user interaction for you.

You can access Keyboard Maestro variables by using environment variables or by using the Keyboard Maestro Engine application (7.1+) :

var kme = Application("Keyboard Maestro Engine");
kme.getvariable('Var');
kme.setvariable('Var', { to: "Hello World!" });

There is lots of good information on, and examples for, JavaScript For Automation on the forum, for example in the topic Learning & Using AppleScript & JavaScript for Automation (JXA)

action/Execute_a_JavaScript_For_Automation.1461809924.txt.gz · Last modified: 2016/04/27 22:18 by peternlewis