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
Next revision Both sides next revision
AppleScript [2017/06/04 22:09]
JMichaelTX [Get Existing Variable]
AppleScript [2017/10/04 02:52]
peternlewis [Examples]
Line 1: Line 1:
 ====== Using AppleScript to Get and Set Keyboard Maestro Variables ====== ====== Using AppleScript to Get and Set Keyboard Maestro Variables ======
-\\+
 ===== Get and Set Variables ===== ===== Get and Set Variables =====
  
Line 67: Line 67:
 ``` ```
  
 +To get or set 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+).
 +
 +```applescript
 +set inst to system attribute "​KMINSTANCE"​
 +tell application "​Keyboard Maestro Engine"​
 + set v to getvariable "​LocalVar"​ instance inst
 + setvariable "​LocalOut"​ instance inst to "​FromAS"​
 +end tell
 +v
 +```
  
 **For more details, see [[manual:​Scripting|Scripting article in the Manual Section]].** **For more details, see [[manual:​Scripting|Scripting article in the Manual Section]].**
 +===== Get and Set Dictionary Values =====
  
-----+You can read and write dictionary values from AppleScript. 
 + 
 +```applescript 
 +tell application "​Keyboard Maestro Engine"​ 
 + name of dictionaries 
 +end tell 
 +``` 
 + 
 +```applescript 
 +tell application "​Keyboard Maestro Engine"​ 
 + dictionary keys of dictionary "First Names"​ 
 +end tell 
 +``` 
 + 
 +```applescript 
 +tell application "​Keyboard Maestro Engine"​ 
 + set value of dictionary key "​P"​ of dictionary "First Names" to "​Fred"​ 
 +end tell 
 +```
  
 ===== Prior to Ver 7.1 ===== ===== Prior to Ver 7.1 =====
Line 86: Line 115:
   ​   ​
   --- Compatible with Keyboard Maestro 6+ ---   --- Compatible with Keyboard Maestro 6+ ---
-  --     • Creates the KM Variable ​it does not exist (just like KM 7 setvariable)+  --     • Creates the KM Variable ​if does not exist (just like KM 7 setvariable)
   --     • Returns true if new Variable was created   --     • Returns true if new Variable was created
   ​   ​
AppleScript.txt · Last modified: 2019/03/28 14:41 by JMichaelTX