Scripting_the_Keyboard_Maestro_editor
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| Scripting_the_Keyboard_Maestro_editor [2017/08/31 07:46] – created peternlewis | Scripting_the_Keyboard_Maestro_editor [2018/04/14 23:02] (current) – Removed script from Section 4 because it won't even compile. JMichaelTX | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| The Keyboard Maestro Scripting Definition (sdef) describes all the support, and you can open in in the Script Editor to see more details. | The Keyboard Maestro Scripting Definition (sdef) describes all the support, and you can open in in the Script Editor to see more details. | ||
| - | ```AppleScript | + | FIXME Just adding this until I can provide a more complete script. |
| - | tell app " | + | |
| - | | + | ===== 1. Selecting Lists of Objects in KM8 ===== |
| - | | + | |
| - | make new smart group with properties {name:" | + | The `selection` property will return whatever is selected, and has focus, in the Keyboard Maestro editor. |
| - | set search strings | + | |
| - | + | ||
| - | set enable of macro group "Turn Off" | + | |
| - | | + | ```applescript |
| + | tell application " | ||
| + | |||
| + | --- First Select an Action, Macro, or Macro Group | ||
| + | -- in the KM Editor, then run this script | ||
| + | |||
| + | | ||
| + | set kmClass to class of item 1 of kmList | ||
| + | |||
| + | -->Based on selection, will return one of these: | ||
| + | --> | ||
| + | |||
| + | end tell | ||
| - | tell macro group "New Stuff" to make new macro | + | ``` |
| - | + | ||
| - | set color of action 1 of macro " | + | |
| - | + | ||
| - | | + | |
| - | set selection to global macro group | ||
| - | move first action of macro "Source Macro" to end of actions of macro " | + | ```applescript |
| - | + | tell application | |
| - | delete second action of macro "Target Macro" | + | set selList |
| + | set macroList to selected macros | ||
| + | set grpList to selected | ||
| + | end tell | ||
| + | ``` | ||
| + | |||
| + | |||
| + | ===== 2. Get Current | ||
| + | |||
| + | ```applescript | ||
| + | |||
| + | tell application | ||
| + | # Ver 1.1 2017-09-20 | ||
| | | ||
| - | | + | set macroList to every macro whose selected is true |
| + | |||
| + | --- Make Sure Only ONE Macro is Selected --- | ||
| + | |||
| + | if ((count of macroList) = 1) then | ||
| + | set oMacro to item 1 of macroList | ||
| + | else | ||
| + | error " | ||
| + | end if | ||
| + | |||
| + | --- Now We can Get/Set Macro Properties --- | ||
| + | |||
| + | set macroName to name of oMacro | ||
| + | |||
| + | return macroName | ||
| + | |||
| + | end tell | ||
| + | ``` | ||
| + | |||
| + | ===== 3. Macro Groups ===== | ||
| + | |||
| + | **Disable a Macro Group** | ||
| + | |||
| + | <code applescript> | ||
| + | tell application | ||
| + | set enabled of macro group "Macro Group Name" to false | ||
| + | end tell | ||
| + | </ | ||
| + | |||
| + | **Edit a Macro Group** | ||
| + | |||
| + | <code applescript> | ||
| + | tell application " | ||
| + | editMacro "Macro Group Name or UID" | ||
| + | end tell | ||
| + | </ | ||
| + | |||
| + | **Get the list of currently selected macro groups** | ||
| + | |||
| + | <code applescript> | ||
| + | tell application " | ||
| + | set groupList to selected macro groups | ||
| + | end tell | ||
| + | </ | ||
| + | |||
| + | ===== 4. Get and Create Variety of Editor Objects ===== | ||
| + | |||
| + | FIXME [JMichaelTX: | ||
| + | |||
| + | |||
| + | ===== 5. Create Macro Group and Macros ===== | ||
| + | |||
| + | Before you use a macro group you probably want to check if it exists. The following example tests for the macro group' | ||
| + | |||
| + | (This test is case-insensitive. For example macro group " | ||
| + | |||
| + | ```applescript | ||
| + | tell application " | ||
| + | set macroGroup to getvariable " | ||
| + | if (macroGroup = "" | ||
| + | end tell | ||
| + | |||
| + | tell application " | ||
| + | if exists macro group macroGroup then | ||
| + | return true | ||
| + | else | ||
| + | return false | ||
| + | end if | ||
| + | end tell | ||
| + | ``` | ||
| - | set m to duplicate action 1 of macro "Macro33" | + | Here is a full example that creates a macro group called |
| - | | + | ```applescript |
| - | | + | tell application id " |
| + | set mg to make new macro group with properties {name:"Multiple Clipboards"} | ||
| + | tell mg | ||
| + | repeat with i from 1 to 9 | ||
| + | set m to make new macro with properties {name:" | ||
| + | tell m | ||
| + | make new trigger with properties {xml:"< | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | make new action with properties {xml:"< | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | end tell | ||
| + | set m to make new macro with properties {name:" | ||
| + | tell m | ||
| + | make new trigger with properties {xml:"< | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | make new action with properties {xml:"< | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | end tell | ||
| + | end repeat | ||
| + | end tell | ||
| end tell | end tell | ||
| ``` | ``` | ||
| + | You can get XML by creating sample macros and then using the Copy as XML in the Edit menu. | ||
Scripting_the_Keyboard_Maestro_editor.1504165588.txt.gz · Last modified: by peternlewis
