This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
action:Execute_a_JavaScript_in_Custom_Prompt [2016/07/30 14:30] JMichaelTX ADD Example with screenshot |
action:Execute_a_JavaScript_in_Custom_Prompt [2023/11/28 03:07] (current) peternlewis [See Also] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{:action:javascript-icon.png?nolink|}} | + | ====== Execute JavaScript in Custom HTML Prompt ====== |
- | ====== Execute JavaScript in Custom HTML Prompt Action ====== | + | |
+ | The //Execute JavaScript in Custom HTML Prompt// action let you execute JavaScript in a [[action:Custom_HTML_Prompt|Custom HTML Prompt]] window. | ||
- | The Execute JavaScript in Custom Prompt action (version 7.1+) allows you to execute a specified JavaScript in any active Keyboard Maestro [[action:Custom_HTML_Prompt|Custom HTML Prompt]]. | + | {{ execute-javascript-in-custom-html-prompt-action.png?nolink&674x161 | Execute JavaScript in Custom HTML Prompt Action }} |
- | The **Execute JavaScript in Custom Prompt** action is the functional equivalent for the Custom HTML Prompt to these actions: | + | This action allows you to execute a specified JavaScript, either from a file or text entered in the Action itself, and return the results. |
- | * [Execute JavaScript in Safari](https://wiki.keyboardmaestro.com/action/Execute_a_JavaScript_in_Google_Chrome) | + | ===== Specify the Custom HTML Prompt ===== |
- | * [Execute JavaScript in Chrome](https://wiki.keyboardmaestro.com/action/Execute_a_JavaScript_in_Google_Chrome) | + | |
- | ===== Example ===== | + | You can specify a [[action:Custom_HTML_Prompt]] with a matching [[action:Custom_HTML_Prompt#HTML_Window_Design|data-kmwindowid]] to apply the JavaScript to, otherwise it will be applied to all open Custom HTML Prompt windows. |
- | {{:action:km-7.2-execute-script-in-html-prompt-example.png?nolink|}} | + | ===== Options for Returning Results ===== |
- | Note the purpose of this example is to close an existing HTML Prompt window, and it calls a custom JavaScript function already in the Custom HTML Prompt. The Action option of "asynchronously" is chosen to avoid timeout of the Action. Otherwise, the Action will wait for a response from the HTML Prompt, which will never come. | + | * ignore results. |
+ | * display results in a window. | ||
+ | * display results briefly. | ||
+ | * display results large. | ||
+ | * type results. | ||
+ | * paste results. | ||
+ | * save results to variable. | ||
+ | * append results to variable. | ||
+ | * save results to the system clipboard or a named clipboard. | ||
+ | * save results to a file. | ||
+ | * asynchronously — the script runs while the macro continues on, no results are returned. | ||
- | ===== Source of Script ===== | + | 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 ===== | ||
- | The JavaScript may be from any of the following: | + | You can use the window.KeyboardMaestro facilities of the [[action:Custom_HTML_Prompt|Custom HTML Prompt]] to read and write Keyboard Maestro variables. |
- | * From a JavaScript file | + | ===== See Also ===== |
- | * From the text script in the Action | + | |
- | * Using any custom functions in the HTML Prompt. | + | |
- | ===== Target of Script ===== | + | * [[actions:Browser_Actions|Browser Actions]] |
- | + | * [[actions:Browser_Window_Actions|Browser Window Actions]] | |
- | The JavaScript is executed in a specific [[action:Custom_HTML_Prompt]] action with a matching [[action:Custom_HTML_Prompt#HTML_Window_Design|data-kmwindowid]], or all Custom HTML Prompts if no windowid is specified. | + | * [[actions:Browser_Form_Actions|Browser Form Actions]] |
- | + | * [[actions:Wait_For_Browser_to_Finish_Loading| Wait For Browser to Finish Loading actions]] | |
- | + | ||
- | + | ||
- | + | ||
- | ===== Results of Action ===== | + | |
- | + | ||
- | This Action can (optionally) return the results of the JavaScript: | + | |
- | + | ||
- | * ignore results | + | |
- | * display results in a window | + | |
- | * display results briefly | + | |
- | * display results large | + | |
- | * type results | + | |
- | * paste results | + | |
- | * save results to variable | + | |
- | * save results to clipboard | + | |
- | * Either the system clipboard or a named clipboard | + | |
- | * asynchronously | + | |
- | * Results are **not** saved | + | |
- | * The macro immediately continues to the next action, which runs in parallel with the current action | + | |
- | + | ||
- | 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. | + | |
- | ===== Access to Keyboard Maestro Variables ===== | + | === Actions === |
- | The JavaScript can access variables by using the window.KeyboardMaestro functions described in the [Custom HTML Prompt](https://wiki.keyboardmaestro.com/action/Custom_HTML_Prompt) action. | + | * [[action:Execute_a_JavaScript_in_Front_Browser|Execute a JavaScript in Front Browser]] |
+ | * [[:Actions|See all Actions]] | ||
- | ===== Related Forum Topics ===== | + | ==== Forum ==== |
- | * [Execute JavaScript in Custom Prompt Question ](https://forum.keyboardmaestro.com/t/execute-javascript-in-custom-prompt-question/4491) | + | - [[https://forum.keyboardmaestro.com/t/execute-javascript-in-custom-prompt-question/4491|Execute JavaScript in Custom Prompt Question]] |