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 [2018/07/03 21:29]
JMichaelTX [Using AppleScript to Get and Set Keyboard Maestro Variables]
AppleScript [2025/02/27 01:45] (current)
peternlewis [Local & Instance Variables]
Line 3: Line 3:
 Keyboard Maestro Version 7.1 introduced a streamlined way to Get and Set Keyboard Maestro Variables from AppleScript. Keyboard Maestro Version 7.1 introduced a streamlined way to Get and Set Keyboard Maestro Variables from AppleScript.
  
-In AppleScript,​ you can tell the application "Keyboard Maestro ​Engine"​ to:+In AppleScript,​ you can access ​Keyboard Maestro ​variables like this:
  
-    ​getvariable <KM Variable Name> +```applescript 
-    setvariable <KM Variable Name> to <New Value>+tell application "​Keyboard Maestro Engine"​ 
 +    set v to getvariable ​"<KM Variable Name>" 
 +    setvariable ​"<KM Variable Name>" ​to "<New Value>
 +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.
Line 76: 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.1530667751.txt.gz · Last modified: 2018/07/03 21:29 by JMichaelTX