User Tools

Site Tools


action:Execute_a_JavaScript_in_Google_Chrome

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

Execute JavaScript in Browser

The Execute JavaScript Action is available ONLY for Safari, Google Chrome, and, as of Ver 7.1, Custom HTML Prompt

Options for Returning Results

  • ignore results.
  • display results in a window.
  • display results briefly.
  • display results large.
  • type results.
  • paste results.
  • save results to variable.
  • save results to the system clipboard or a named clipboard.
  • save results asynchronously — the action runs while the macro continues on.

If the results are to be saved to a variable or a clipboard then further text areas appear in the action allowing you to specify the variable or specific clipboard.

Using Keyboard Maestro Variables

JavaScript can only GET Keyboard Maestro variables. They cannot be set:

snippet.javascript
var myData = document.kmvar.My_KM_Data

If your Keyboard Maestro Variable contains spaces, they must be replaced with underscores in the JavaScript, for example:

  Keyboard Maestro Variable Name:  My KM Data
  JavaScript Reference:            document.kmvar.My_KM_Data

Saving Results to Keyboard Maestro Variables

If you need to set a Keyboard Maestro Variable from the Browser JavaScript, then use a JavaScript return to return the data to the Keyboard Maestro Action, which can be set to save the results as a Keyboard Maestro Variable.

If you need to set more than one Keyboard Maestro Variable, one approach is to return the data for each variable on a separate line (or with delimiters of your choice), and then parse in a following Keyboard Maestro Search Action using RegEx.

Examples

1. Return Data for Multiple Variables

action/Execute_a_JavaScript_in_Google_Chrome.1490155871.txt.gz · Last modified: 2017/03/22 00:11 by peternlewis