Scripting_the_Keyboard_Maestro_editor
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| Scripting_the_Keyboard_Maestro_editor [2017/09/20 20:29] – ADD example to get current macro JMichaelTX | 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. | ||
| - | ===== 1. Get Current Macro Object | + | FIXME Just adding this until I can provide a more complete script. |
| + | |||
| + | ===== 1. Selecting Lists of Objects in KM8 ===== | ||
| + | |||
| + | The `selection` property will return whatever is selected, and has focus, in the Keyboard Maestro editor. | ||
| ```applescript | ```applescript | ||
| + | tell application " | ||
| + | | ||
| + | --- First Select an Action, Macro, or Macro Group | ||
| + | -- in the KM Editor, then run this script | ||
| + | | ||
| + | set kmList to selection | ||
| + | set kmClass to class of item 1 of kmList | ||
| + | | ||
| + | -->Based on selection, will return one of these: | ||
| + | --> | ||
| + | | ||
| + | end tell | ||
| + | ``` | ||
| + | |||
| + | |||
| + | ```applescript | ||
| tell application " | tell application " | ||
| + | set selList to selection | ||
| + | set macroList to selected macros | ||
| + | set grpList to selected macro groups | ||
| + | end tell | ||
| + | ``` | ||
| + | |||
| + | |||
| + | ===== 2. Get Current Macro Object ===== | ||
| + | |||
| + | ```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 oMacro to first macro whose selected is true | ||
| set macroName to name of oMacro | set macroName to name of oMacro | ||
| | | ||
| Line 19: | Line 63: | ||
| ``` | ``` | ||
| - | ===== 2. Get and Create Variety of Editor Objects | + | ===== 3. Macro Groups |
| + | **Disable a Macro Group** | ||
| - | ```applescript | + | < |
| - | tell app " | + | tell application |
| + | set enabled of macro group "Macro Group Name" to false | ||
| + | end tell | ||
| + | </ | ||
| - | | + | **Edit a Macro Group** |
| - | | + | |
| - | make new smart group with properties {name:"Enabled", search strings: | + | <code applescript> |
| - | set search strings of smart group "Disabled" | + | tell application |
| - | | + | |
| - | set enable of macro group "Turn Off" to false | + | end tell |
| + | </ | ||
| - | set name of macro 1 to " | + | **Get the list of currently selected |
| - | tell macro group "New Stuff" | + | <code applescript> |
| - | | + | tell application |
| - | | + | |
| - | | + | end tell |
| - | select action 1 through 3 of action 2 of macro " | + | </ |
| - | set selection to global macro group | + | ===== 4. Get and Create Variety of Editor Objects ===== |
| - | move first action of macro " | + | FIXME [JMichaelTX: |
| - | + | ||
| - | move macro " | + | |
| - | move (every macro of macro group " | + | |
| - | move macro 2 of macro group " | + | |
| - | | ||
| - | | ||
| - | | ||
| - | set m to duplicate action 1 of macro "Macro33" to after action 2 of macro "Macro32" | + | ===== 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 "Firefox" | ||
| + | |||
| + | ```applescript | ||
| + | tell application " | ||
| + | set macroGroup | ||
| + | if (macroGroup = "" | ||
| + | end tell | ||
| - | | + | tell application |
| - | | + | if exists macro group macroGroup then |
| + | return true | ||
| + | else | ||
| + | return false | ||
| + | end if | ||
| end tell | end tell | ||
| ``` | ``` | ||
| - | ===== 3. Create Macro Group and Macros ===== | ||
| Here is a full example that creates a macro group called " | Here is a full example that creates a macro group called " | ||
Scripting_the_Keyboard_Maestro_editor.1505939356.txt.gz · Last modified: by JMichaelTX
