How to create a macro that renames current selected macro? [SOLVED]

I have a macro that creates a script from my currently selected KM macro that is then available when I use Raycast. On all of those macros that are converted to Raycast scripts I add "(available via Raycast)" at the end of the macro's name like this:

On my macro that creates the script I would like it to start by checking if the macro's name contains that text at the end and if not, rename the macro and then continue running the macro to create the script.

You can use AppleScript to rename a macro. To rename the currently selected (or the first if multiple):

tell application "Keyboard Maestro"
	set theMacro to first item of (get selectedMacros)
	if name of macro id theMacro does not end with "(available via Raycast)" then
		set name of macro id theMacro to (name of macro id theMacro & " (available via Raycast)")
		return 1
		return 0
	end if
end tell

Difficult to be sure without seeing your macro, but you can probably just drop that in as an AppleScript action. If you set that action to "Save results to a variable" can then test the result -- if it is "1" then you renamed the macro and should continue running the script, if it is "0" it was already named so needn't be processed.

Do beware in case renaming your macro affects the rest of your processing macro!

1 Like

Thank you so much. That worked like a charm.
I just added it to the beginning of the macro that creates the script, so there's no need to save it as a variable.

Looking at the script, and me being a newbie when it comes to AS, it still amazes me that sometimes the script mimics how we speak. Very interesting language.