User Tools

Site Tools


AppleScript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
AppleScript [2025/02/27 01:34]
peternlewis [Using AppleScript to Get and Set Keyboard Maestro Variables]
AppleScript [2025/02/27 01:45] (current)
peternlewis [Local & Instance Variables]
Line 7: Line 7:
 ```applescript ```applescript
 tell application "​Keyboard Maestro Engine"​ tell application "​Keyboard Maestro Engine"​
-    getvariable <KM Variable Name> +    ​set v to getvariable ​"<KM Variable Name>" 
-    setvariable <KM Variable Name> to <New Value>+    setvariable ​"<KM Variable Name>" ​to "<New Value>"
 end tell end tell
 ``` ```
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 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
 ``` ```
  
AppleScript.1740638090.txt.gz · Last modified: 2025/02/27 01:34 by peternlewis