User Tools

Site Tools


actions:Execute_a_JavaScript_in_Browser

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

The Execute a JavaScript in Browser actions let you execute a JavaScript in the active web browser page.

Like other browser actions, these actions work with Safari or Google Chrome (or whichever of the two was last at the front).
Alternatively, you can execute JavaScript in a specified Custom HTML Prompt.

This action allows you to execute a specified JavaScript, either from a file or text entered in the Action itself, and return the results.

If you need to access other Mac apps, see Execute JavaScript for Automation (JXA) Action.

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.
  • asynchronously — the action runs while the macro continues on, no results are returned.

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. If your Keyboard Maestro Variable contains spaces, they must be replaced with underscores in the JavaScript, for example:

snippet.javascript
// Get Keyboard Maestro variable "My KM Data"
var myData = document.kmvar.My_KM_Data

Saving Results to Keyboard Maestro Variables

If you need to set a Keyboard Maestro Variable from the 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 Search using Regular Expression.

For example:

See Also

Actions

Forum

actions/Execute_a_JavaScript_in_Browser.1504159348.txt.gz · Last modified: 2017/08/31 02:02 by peternlewis