action:Execute_an_AppleScript
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| action:Execute_an_AppleScript [2023/09/13 03:04] – [Using Keyboard Maestro Variables] peternlewis | action:Execute_an_AppleScript [2025/02/27 06:45] (current) – [Using Keyboard Maestro Variables] peternlewis | ||
|---|---|---|---|
| Line 49: | Line 49: | ||
| ===== Using Keyboard Maestro Variables ===== | ===== Using Keyboard Maestro Variables ===== | ||
| - | :!: **See [[: | + | Keyboard Maestro sets the environment variables for the script |
| - | Keyboard Maestro sets the environment variables for the script to include all your variables, using a prefix of `KMVAR_` and your variable name with spaces changed in to underscores | + | Also, you can (7.1+) access |
| - | By default, all variables are included, but you can select No Variables, or specific variables as desired using the popup menu next to the script (v11.0+). | + | ```applescript |
| - | + | tell application " | |
| - | In AppleScript with Keyboard Maestro Version 7.1+, you can tell the application " | + | |
| - | + | setvariable | |
| - | getvariable <KM Variable Name> | + | end tell |
| - | setvariable <KM Variable Name> to <New Value> | + | ``` |
| 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 ===== | ||
action/Execute_an_AppleScript.1694574296.txt.gz · Last modified: by peternlewis
