JXA Bug: Create Macro in selected Macro Group

, ,

@Peter, Script Editor throws an error when pushing to a specific macro collection. Do you know if this is a bug?

Code:

(() => {
    const km = Application('Keyboard Maestro');
	const selnMacroGroups = km.selectedMacroGroups();
	
	const macroObject = km.Macro({name:"New Macro"})
	return selnMacroGroups[0].macros.push(macroObject)
})();

I successfully created actions inside the selected macro.

Code:

(() => {
    const km = Application('Keyboard Maestro');
	const selnMacro = km.selectedMacros();
	
	const oAction = km.Action()
	return selnMacro[0].actions.push(oAction)
})();

Would be possible to fix it? Thanks in advance.

You probably can’t “push” to a macro group because macro groups have an unordered set of macros.

But I don’t really know, as I am not much of an expert on JXA, so someone who knows more will have to figure out how to translate creating a macro within the selected macro group from AppleScript to JXA.

Thanks for the reply, Peter.

What surprises me is that I can successfully push to the global macro collection.
This works perfectly.

(() => {
    const km = Application('Keyboard Maestro');
	
	const oMacro = km.Macro({name:'New Macro'})
    
    // km.macros -- Global macro collection
	return km.macros.push(oMacro) 
})();

But can’t to specific macro collection of a macro group.