This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
actions:Execute_a_JavaScript_in_Browser [2017/08/31 02:07] peternlewis |
actions:Execute_a_JavaScript_in_Browser [2017/08/31 02:09] peternlewis |
||
---|---|---|---|
Line 1: | Line 1: | ||
The *Execute a JavaScript in Browser* actions let you execute a JavaScript in the active web browser page. | The *Execute a JavaScript in Browser* actions let you execute a JavaScript in the active web browser page. | ||
- | Like other [[Browser_Actions|browser actions]], these actions work with Safari or Google Chrome (or whichever of the two was last at the front). | + | Like other [[Browser_Actions|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 [[action:Custom_HTML_Prompt|Custom HTML Prompt]] window. | + | Alternatively, you can execute JavaScript in a specified [[action:Custom_HTML_Prompt|Custom HTML Prompt]] window (v7.1+). |
This action allows you to execute a specified JavaScript, either from a file or text entered in the Action itself, and return the results. | This action allows you to execute a specified JavaScript, either from a file or text entered in the Action itself, and return the results. | ||
Line 27: | Line 27: | ||
===== Using Keyboard Maestro Variables ===== | ===== 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: | + | JavaScript in browsers 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: |
```javascript | ```javascript | ||
Line 36: | Line 36: | ||
===== Saving Results to Keyboard Maestro Variables ===== | ===== 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 a Keyboard Maestro Variable from the JavaScript in a browser, then use the JavaScript return value 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 [[action: Search_using_Regular_Expression|Search using Regular Expression]]. | 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 [[action: Search_using_Regular_Expression|Search using Regular Expression]]. |