Automating the Keyboard Maestro Editor with AppleScript


AppleScripts for the Keyboard Maestro Editor

  • Versions 9.x and 10.x

Select Macro Name or Group Name or Smart Group Name Field for Editing.


--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/07/25 03:06
# dMod: 2021/09/30 17:17
# Appl: Keyboard Maestro & System Events
# Task: Select Macro Name or Group Name or Smart Group Name Field for Editing.
# Libs: ELb
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Keyboard_Maestro, @Select, @Name, @Field
--------------------------------------------------------

tell application "Keyboard Maestro"
   set kmVersion to its version
end tell

if kmVersion starts with "9." then
   
   tell application "System Events"
      tell application process "Keyboard Maestro"
         tell (first window whose subrole is "AXStandardWindow")
            tell group 1
               tell splitter group 1
                  tell scroll area 3
                     
                     tell scroll bar 1
                        if value ≠ 0 then set value to 0
                     end tell
                     
                     if exists (first text field whose accessibility description is "Macro Name") then
                        tell (first text field whose accessibility description is "Macro Name")
                           set focused to true
                        end tell
                        
                     else if exists (first text field whose accessibility description is "Macro Group Name") then
                        tell (first text field whose accessibility description is "Macro Group Name")
                           set focused to true
                        end tell
                        
                     else if exists (first text field whose accessibility description is "Smart Group Name") then
                        tell (first text field whose accessibility description is "Smart Group Name")
                           set focused to true
                        end tell
                        
                     end if
                     
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
else if kmVersion starts with "10." then
   
   tell application "System Events"
      tell application process "Keyboard Maestro"
         tell (first window whose subrole is "AXStandardWindow")
            tell group 6
               tell splitter group 1
                  tell scroll area 3
                     
                     tell scroll bar 1
                        if value ≠ 0 then set value to 0
                     end tell
                     
                     if exists (first text field whose accessibility description is "Macro Name") then
                        
                        tell (first text field whose accessibility description is "Macro Name")
                           set focused to true
                        end tell
                        
                     else if exists (first text field whose accessibility description is "Macro Group Name") then
                        tell (first text field whose accessibility description is "Macro Group Name")
                           set focused to true
                        end tell
                        
                     else if exists (first text field whose accessibility description is "Smart Group Name") then
                        tell (first text field whose accessibility description is "Smart Group Name")
                           set focused to true
                        end tell
                        
                     end if
                     
                     
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
   
   
end if

--------------------------------------------------------

(*
--------------------------------------------------------

REVISION NOTES:

2018/01/12 00:36 ⇢ Streamlined for pure speed.
2018/04/10 03:45 ⇢ More flexibly handling macro group name or macro name ⇢ by name instead of number.
2019/02/20 04:29 ⇢ Added “Smart Group Name” to selector choice.

--------------------------------------------------------
*)

Select the First Action of the Macro Currently Being Edited


--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/06/30 23:41
# dMod: 2021/10/09 20:28
# Appl: Keyboard Maestro & System Events
# Task: Select First Action of Current Macro
#     : Scroll if necessary.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Keyboard_Maestro, @Select, @Name, @Field
--------------------------------------------------------

tell application "Keyboard Maestro" to set kmVersion to version

if kmVersion starts with "9." then
   # Keyboard Maestro v9.x.
   tell application "System Events"
      tell application process "Keyboard Maestro"
         tell (first window whose subrole is "AXStandardWindow")
            tell group 1
               tell splitter group 1
                  tell scroll area 3
                     
                     tell scroll bar 1
                        try
                           set value to 0
                        end try
                     end tell
                     
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
else if kmVersion starts with "10." then
   
   # Keyboard Maestro v10.x.
   tell application "System Events"
      tell application process "Keyboard Maestro"
         tell (first window whose subrole is "AXStandardWindow")
            tell group 6
               tell splitter group 1
                  tell scroll area 3
                     tell scroll bar 1
                        try
                           set value to 0
                        end try
                     end tell
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
end if

--------------------------------------------------------

tell application "Keyboard Maestro"
   
   set selectedMacroList to selected macros
   
   if length of selectedMacroList = 0 then
      error "No macros are selected!"
      
   else if length of selectedMacroList = 1 then
      set currentMacro to item 1 of selectedMacroList
      
   else if length of selectedMacroList > 1 then
      error "Too many macros are selected!"
      
   end if
   
   select the first action of the currentMacro
   
end tell

--------------------------------------------------------

(* CHANGE NOTES:

   - 2021/09/30 01:39
      - Added descriminator for KM 9 and KM 10.
      
*)

--------------------------------------------------------

Select the Last Action of the Macro Currently Being Edited

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/06/30 23:41
# dMod: 2021/09/30 01:44
# Appl: Keyboard Maestro & System Events
# Task: Select Last Action of Current Macro
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Keyboard_Maestro, @Select, @Name, @Field
--------------------------------------------------------

tell application "Keyboard Maestro" to set kmVersion to version

if kmVersion starts with "9." then
   # Keyboard Maestro v9.x.
   tell application "System Events"
      tell application process "Keyboard Maestro"
         tell (first window whose subrole is "AXStandardWindow")
            tell group 1
               tell splitter group 1
                  tell scroll area 3
                     
                     tell scroll bar 1
                        if value ≠ 1 then set value to 1
                     end tell
                     
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
else if kmVersion starts with "10." then
   
   # Keyboard Maestro v10.x.
   tell application "System Events"
      tell application process "Keyboard Maestro"
         tell (first window whose subrole is "AXStandardWindow")
            tell group 6
               tell splitter group 1
                  tell scroll area 3
                     tell scroll bar 1
                        if value ≠ 1 then set value to 1
                     end tell
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
end if

tell application "Keyboard Maestro"
   
   set selectedMacroList to selected macros
   
   if length of selectedMacroList = 0 then
      error "No macros are selected!"
      
   else if length of selectedMacroList = 1 then
      set currentMacro to item 1 of selectedMacroList
      
   else if length of selectedMacroList > 1 then
      error "Too many macros are selected!"
      
   end if
   
   select the last action of the currentMacro
   
end tell

--------------------------------------------------------

(* CHANGE NOTES:

   - 2021/09/30 01:39
      - Added descriminator for KM 9 and KM 10.
      
*)

--------------------------------------------------------
3 Likes