Hey Folks,
Peter spent a lot of effort making Keyboard Maestro 8 more AppleScriptable. (Thank you Peter!)
And this makes many things easy to do that were difficult or impossible in previous versions of KM.
When I’m testing something in Keyboard Maestro or creating a new macro I almost always use (or at least start out with) the same test macro:
Generic-Test 01
Therefore I want to get to that macro quickly quite often.
Using the following script I can manage that spectacular feat with a keystroke.
The user is REQUIRED to provide names for their test-group and test-macro — see User Settings in the script.
If the designated group or the macro don’t exist they will be created as necessary.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/08/21 21:37
# dMod: 2017/11/17 04:46
# Appl: Keyboard Maestro
# Task: Edit 'Generic Test 1' Macro of macro group 'Test Group'.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro_8, @KM8, @Editor, @Edit, @Macro
------------------------------------------------------------------------------
try
---------------------------------------------------------------------------
# User Settings:
---------------------------------------------------------------------------
set macroGroupName to "Test Group"
set macroName to "Generic-Test 01"
---------------------------------------------------------------------------
tell application "Keyboard Maestro"
------------------------------------------------------------------------
# Make sure the designated macro group and macro exist.
# Create one or both of them as necessary.
------------------------------------------------------------------------
if (exists of macro group macroGroupName) = false then
set newGroup to make new macro group with properties {name:macroGroupName}
select newGroup
end if
if (exists of macro macroName) = false then
tell macro group macroGroupName
set newMacro to make new macro with properties {name:macroName}
select newMacro
return --» script ends here IF a new macro is created.
end tell
end if
------------------------------------------------------------------------
# Select the macro group if necessary.
------------------------------------------------------------------------
if selected of macro group macroGroupName = false or length of (get selected macro groups) > 1 then
select macro group macroGroupName
end if
------------------------------------------------------------------------
# Select the macro for editing.
------------------------------------------------------------------------
editMacro macroName
------------------------------------------------------------------------
end tell
on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell application (path to frontmost application as text) to set ddButton to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy Error Message" then set the clipboard to e
end try
end if
end try
------------------------------------------------------------------------------
Enjoy.
-Chris