AppleScript
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| AppleScript [2017/06/05 02:08] – [Create & Set Variable] Replace script with Ver 6+ compatible JMichaelTX | AppleScript [2025/02/27 06:45] (current) – [Local & Instance Variables] peternlewis | ||
|---|---|---|---|
| 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 ===== | ||
| 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, | + | In AppleScript, |
| - | | + | ```applescript |
| - | setvariable <KM Variable Name> to <New Value> | + | tell application " |
| + | set v to getvariable | ||
| + | setvariable | ||
| + | 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. | ||
| - | ==== Examples | + | **For more details, see:** |
| + | - [[manual: | ||
| + | - [[action: | ||
| + | |||
| + | ===== Global Variables | ||
| + | |||
| + | Global Variables (available in //all// macros) may be got and set like this: | ||
| ```applescript | ```applescript | ||
| Line 44: | Line 52: | ||
| ``` | ``` | ||
| + | **Real-World Example** | ||
| Normally, you would not have both a GET and a SET variable within the same AppleScript tell block.\\ | Normally, you would not have both a GET and a SET variable within the same AppleScript tell block.\\ | ||
| Line 50: | Line 58: | ||
| ```applescript | ```applescript | ||
| + | ### Requires Keyboard Maestro 7.1+ ### | ||
| + | |||
| --- GET REQUIRED KM VARIABLES --- | --- GET REQUIRED KM VARIABLES --- | ||
| Line 67: | Line 77: | ||
| ``` | ``` | ||
| + | ===== Local & Instance Variables ===== | ||
| - | **For more details, see [[manual: | ||
| - | ---- | + | To get or set [[manual: |
| + | |||
| + | ```applescript | ||
| + | set kmInst to system attribute " | ||
| + | tell application " | ||
| + | set v to getvariable " | ||
| + | setvariable " | ||
| + | end tell | ||
| + | |||
| + | log v | ||
| + | ``` | ||
| + | |||
| + | |||
| + | ===== Dictionary Values ===== | ||
| + | |||
| + | You can read and write [[manual: | ||
| + | |||
| + | ```applescript | ||
| + | ### Requires Keyboard Maestro 8.0+ ### | ||
| + | |||
| + | tell application " | ||
| + | set kmDictList to name of dictionaries | ||
| + | set dictKeyList to dictionary keys of dictionary "First Names" | ||
| + | |||
| + | set value of dictionary key " | ||
| + | end tell | ||
| + | ``` | ||
| ===== Prior to Ver 7.1 ===== | ===== Prior to Ver 7.1 ===== | ||
| Line 86: | Line 122: | ||
| | | ||
| --- Compatible with Keyboard Maestro 6+ --- | --- Compatible with Keyboard Maestro 6+ --- | ||
| - | -- • Creates the KM Variable | + | -- • Creates the KM Variable |
| -- • Returns true if new Variable was created | -- • Returns true if new Variable was created | ||
| | | ||
| Line 116: | Line 152: | ||
| - | ==== Get Existing | + | ==== Get Variable ==== |
| + | (returns empty string "" | ||
| ```applescript | ```applescript | ||
| Line 125: | Line 162: | ||
| --- Compatible with Keyboard Maestro 6+ --- | --- Compatible with Keyboard Maestro 6+ --- | ||
| - | -- • Returns "" | + | -- • Returns "" |
| | | ||
| tell application " | tell application " | ||
AppleScript.1496628489.txt.gz · Last modified: by JMichaelTX
