action:Execute_an_AppleScript
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| action:Execute_an_AppleScript [2021/07/21 21:58] – ADD section on error handling JMichaelTX | action:Execute_an_AppleScript [2025/02/27 06:45] (current) – [Using Keyboard Maestro Variables] peternlewis | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| **There are two setup options:** | **There are two setup options:** | ||
| ^ Setup Option ^ Choices\\ (Default shown first) ^ | ^ Setup Option ^ Choices\\ (Default shown first) ^ | ||
| - | | Script location | Execute text script (type or paste script into Action text field)\\ Execute script file (This is faster if it is a compiled script file `.scpt`) | | + | | Script location | Execute text script (type or paste script into Action text field)\\ Execute script file (This may be faster if it is a compiled script file `.scpt`) | |
| | Script Results | Ignored.\\ Displayed in a floating window.\\ Displayed briefly in a Notification.\\ Typed in the current text field that has focus.\\ Pasted in text field that has focus.\\ Saved to a Keyboard Maestro Variable.\\ Saved to the System or Named Clipboard.\\ Ignore Results and run // | | Script Results | Ignored.\\ Displayed in a floating window.\\ Displayed briefly in a Notification.\\ Typed in the current text field that has focus.\\ Pasted in text field that has focus.\\ Saved to a Keyboard Maestro Variable.\\ Saved to the System or Named Clipboard.\\ Ignore Results and run // | ||
| Line 23: | Line 23: | ||
| {{: | {{: | ||
| + | |||
| + | When editing the script, you can press < | ||
| If the script fails, the action will fail (v9.0+), potentially aborting the macro. | If the script fails, the action will fail (v9.0+), potentially aborting the macro. | ||
| Line 47: | Line 49: | ||
| ===== Using Keyboard Maestro Variables ===== | ===== Using Keyboard Maestro Variables ===== | ||
| - | :!: **See [[: | + | Keyboard Maestro sets the environment variables for the script |
| - | In AppleScript with Keyboard Maestro Version | + | Also, you can (7.1+) access |
| - | | + | ```applescript |
| - | setvariable <KM Variable Name> to <New Value> | + | tell application " |
| + | set v to getvariable | ||
| + | setvariable | ||
| + | end tell | ||
| + | ``` | ||
| where both the `<KM Variable Name>` and `<New Value>` are text values. | where both the `<KM Variable Name>` and `<New Value>` are text values. | ||
| - | For example: | + | ===== Local & Instance Variables ===== |
| - | <code applescript> | + | |
| - | tell application " | + | |
| - | </ | + | |
| - | **Using Keyboard Maestro | + | To get or set [[manual:Variables# |
| - | AppleScripts can access variables by using environment variables (using | + | ```applescript |
| + | set kmInst to system attribute | ||
| + | tell application "Keyboard Maestro Engine" | ||
| + | set v to getvariable " | ||
| + | setvariable " | ||
| + | end tell | ||
| - | <code applescript> | + | log v |
| - | set myVar to do shell script "echo $KMVAR_My_KM_Variable" | + | ``` |
| - | </ | + | |
| ===== Error Handling ===== | ===== Error Handling ===== | ||
| Line 89: | Line 96: | ||
| Here is an example of such an Action/ | Here is an example of such an Action/ | ||
| - | | + | ===== See Also ===== |
| - | + | ||
| + | === Actions === | ||
| + | |||
| + | * [[action: | ||
| + | * [[action: | ||
| + | * [[action: | ||
| + | * [[action: | ||
| + | * [[: | ||
| + | |||
action/Execute_an_AppleScript.1626904734.txt.gz · Last modified: by JMichaelTX
