JavaScript_for_Automation
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| JavaScript_for_Automation [2016/05/09 07:28] – JMTX template + add forum links & internal links alain | JavaScript_for_Automation [2019/01/12 17:43] (current) – [Accessing Keyboard Maestro Variables] ADD Link to Get/Set Local/Instance Vars JMichaelTX | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== JavaScript for Automation (JXA) Discussion |
| - | ===== Which Execute JavaScript Should You Use? ===== | + | ===== Scope and Summary |
| + | |||
| + | This Wiki article is a broad topic, which covers these major areas: | ||
| + | |||
| + | - Introduction to JXA | ||
| + | - Using JXA with Keyboard Maestro | ||
| + | - JXA Background | ||
| + | - Comparison with AppleScript | ||
| + | |||
| + | |||
| + | ===== Introduction ===== | ||
| + | |||
| + | Keyboard Maestro supports use of JavaScript in two basic ways: | ||
| + | |||
| + | - Execute JavaScript in a Browser | ||
| + | - Execute JavaScript for Automation (JXA) | ||
| + | |||
| + | This article deals only with the latter, JavaScript for Automation (JXA). | ||
| JavaScript, once a language which ran only in web browsers, can now be used in a variety of environments. From Keyboard Maestro you can: | JavaScript, once a language which ran only in web browsers, can now be used in a variety of environments. From Keyboard Maestro you can: | ||
| Line 9: | Line 26: | ||
| 3. Run it in Custom HTML Prompt windows. | 3. Run it in Custom HTML Prompt windows. | ||
| - | [[https:// | + | =====Using JXA with Keyboard Maestro===== |
| + | |||
| + | ==== JXA Scripts ==== | ||
| + | |||
| + | You can run a JXA script from Keyboard Maestro by either of these _Execute Script_ Actions: | ||
| + | |||
| + | * [[action: | ||
| + | * The JXA script may be accessed as text in the Action, or from a file. | ||
| + | * [[action: | ||
| + | * The JXA script can be embedded in a Shell Script | ||
| + | |||
| + | |||
| + | ==== Accessing Keyboard Maestro Variables ==== | ||
| + | |||
| + | You can access Keyboard Maestro variables (7.1+) from JXA scripts using the Keyboard Maestro Engine application. | ||
| + | |||
| + | <code javascript> | ||
| + | //--- GET A REFERENCE TO THE KM ENGINE --- | ||
| + | var kme = Application(" | ||
| + | |||
| + | //--- GET A KM VARIABLE --- | ||
| + | var myVar = kme.getvariable(' | ||
| + | |||
| + | //--- SET A KM VARIABLE --- | ||
| + | // - Using explicit text | ||
| + | kme.setvariable(' | ||
| + | |||
| + | // - Using a JavaScript Variable | ||
| + | var scriptResults = "Text Determined by the script" | ||
| + | kme.setvariable(' | ||
| + | </ | ||
| + | |||
| + | Also see **[[action: | ||
| + | |||
| + | JXA can get a list of all variables as described on the [forum](https:// | ||
| + | |||
| + | |||
| + | **For more info on using JXA with Keyboard Maestro, see:** | ||
| + | |||
| + | * [[manual: | ||
| + | |||
| + | ===== JXA Background ===== | ||
| + | |||
| + | [[https:// | ||
| 1. With access to the functions and constants of an Automation object, and | 1. With access to the functions and constants of an Automation object, and | ||
| - | 2. with additional access to a lot of low-level Apple system functions through the ObjC object. | + | 2. with additional access to a lot of low-level Apple system functions through the Objective-C |
| - | The first script to try in JXA consists of just one word: | + | You can view the built-in, default function provided by JXA by running this simple, |
| `this` | `this` | ||
| Line 30: | Line 90: | ||
| Keyboard Maestro’s [[action: | Keyboard Maestro’s [[action: | ||
| - | =====The basics – AppleScript | + | |
| + | =====Comparing JXA with AppleScript===== | ||
| ====Evaluating simple expressions==== | ====Evaluating simple expressions==== | ||
| Line 273: | Line 334: | ||
| to follow ... | to follow ... | ||
| - | =====Accessing Keyboard Maestro Variables===== | ||
| - | You can access Keyboard Maestro variables (7.1+) from JXA scripts using the Keyboard Maestro Engine application. | ||
| - | <code javascript> | ||
| - | var kme = Application(" | ||
| - | kme.getvariable(' | ||
| - | kme.setvariable(' | ||
| - | </ | ||
| - | |||
| - | JXA can get a list of all variables as described on the [forum](https:// | ||
| - | |||
| - | =====The Automation interface===== | ||
| - | |||
| - | ===Using the Standard Additions library==== | ||
| - | |||
| - | to follow ... | ||
| - | |||
| - | ===Interacting with scriptable applications=== | ||
| - | |||
| - | to follow ... | ||
| - | |||
| - | =====Using the Safari JSContexts Debugger (El Capitan onwards)===== | ||
| - | |||
| - | to follow ... | ||
| - | |||
| - | =====The ObjC interface===== | ||
| - | |||
| - | to follow ... | ||
| - | |||
| - | ===Basic file functions=== | ||
| - | |||
| - | to follow ... | ||
| - | |||
| - | ===Clipboard functions=== | ||
| - | |||
| - | to follow ... | ||
| - | |||
| - | ===Reading the documentation for simple ObjC functions=== | ||
| - | |||
| - | to follow ... | ||
| ===== See Also ===== | ===== See Also ===== | ||
| Line 334: | Line 356: | ||
| - [[https:// | - [[https:// | ||
| - | - [[https://www.google.fr/ | + | - [[https:// |
JavaScript_for_Automation.1462778936.txt.gz · Last modified: by alain
