This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
AppleScript [2025/02/27 01:40] peternlewis [Using AppleScript to Get and Set Keyboard Maestro Variables] |
AppleScript [2025/02/27 01:45] (current) peternlewis [Local & Instance Variables] |
||
---|---|---|---|
Line 80: | Line 80: | ||
- | To get or set [[manual:Variables#Instance_Variables_v8|Local or Instance Variables]], you must pass the macro execution instance to the `getvariable` or `setvariable` command. The instance is passed in to your script via the KMINSTANCE environment variable (v8.0.3+). | + | To get or set [[manual:Variables#Scope|Local or Instance Variables]], you must pass the macro execution instance to the `getvariable` or `setvariable` command. The instance is passed in to your script via the KMINSTANCE environment variable (v8.0.3+). |
- | + | ||
- | * //Local Variables// are denoted by a Variable with the prefix of "Local". | + | |
- | * //Instance Variables// are denoted by a Variable with the prefix of "Instance". | + | |
```applescript | ```applescript | ||
- | ### Requires Keyboard Maestro 8.0.3+ ### | ||
- | |||
set kmInst to system attribute "KMINSTANCE" | set kmInst to system attribute "KMINSTANCE" | ||
tell application "Keyboard Maestro Engine" | tell application "Keyboard Maestro Engine" | ||
- | set kmLocalVar1 to getvariable "Local__SomeLocalVariable" instance kmInst | + | set v to getvariable "Local__SomeLocalVariable" instance kmInst |
setvariable "Local__FromAS" instance kmInst to "Variable set in AppleScript." | setvariable "Local__FromAS" instance kmInst to "Variable set in AppleScript." | ||
end tell | end tell | ||
- | log kmLocalVar1 | + | log v |
``` | ``` | ||