Copy Macro Group Title and Macro Name via Macro Actions?

I'm trying to build a macro to help me extract my Found Image images from Editor into external images and replace the Found Image Image with a reference to the path. When I copy the image from the Found Image Image field with CMD+C, I'd like to have KM then:

  1. Copy the Group and Macro titles to variables
  2. Create a new Preview image from the clipboard (Found Image)
  3. Save the image to specific folder and with a filename incorporating the Macro Group and Macro names.

Step 1 is where I'm struggling. How can I copy the currently selected macro's name and group name?

I try my best to help with things like this, but today I can only give you some tips.

  1. The KM Editor is an AppleScript-enabled program so you can probably use AppleScript to help you here, especially with step 1. However I'm a noob at AppleScript so other people will have to help you here.
  2. The macro group and macro name do not uniquely identify your image, because you could have more than one image per macro. So you have to think of a way to address that.

Yes, I have that addressed.

How about these tokens: token:ExecutingMacroGroup [Keyboard Maestro Wiki], There's more listed on the linked page,

I was just working with those tokens yesterday, and I forgot all about them today!

1 Like

Oh, right! I keep forgetting about tokens. I kept searching for things like "Macro name as variable". Thanks, @DanThomas !

I think those tokens are for the currently running macro, whereas I think you are trying to write a macro that deals with other macros.

Yes, but this token:MacroNameForUUID [Keyboard Maestro Wiki] gets me the macro name of the selected macro. So, it's a start.

Extract Found Image Macro (v10.0.2)

Extract Found Image.kmmacros (3.4 KB)

1 Like

I can see you are well ahead of me. Good luck.

1 Like

I made this, which works, but I'm hoping to improve it with automatic inclusion of the Macro Group Name of the target macro: Macro: Extract Found Image Image and Replace with Path

I'm trying to do the same thing as @iampariah. I think this returns the name of the executing macro group, which in this case would be the macro which performs the task, rather than the macro which is being acted upon, whose group we're trying to deduce. My research has come up short too.

1 Like

Hey Neil,

As far as I can see Pariah's last macro works, although it's a bit of a workaround.

This task can be accomplished directly using AppleScript.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/03/18 21:14
# dMod: 2022/03/18 21:14 
# Appl: Keyboard Maestro, Keyboard Maestro Engine
# Task: Get Macro Name Selected Macro and Its Macro Group Name
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Keyboard_Maestro_Engine, @Get, @Macro, @Name, @Selected, @Group
--------------------------------------------------------

tell application "Keyboard Maestro"
   
   set selected_Macros to selectedMacros
   
   if length of selected_Macros is 1 then
      set macroUUID to item 1 of selected_Macros
      set macroRef to macro id macroUUID
      set macroName to name of macroRef
      set macroGroupName to name of macro group of macroRef
   else
      display notification "Problem with number of selected macros!" with title "Keyboard Maestro" subtitle "························" sound name "Tink"
   end if
   
end tell

# Send variables to Keyboard Maestro:
set kmInstance to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
   setvariable "local_MacroName" instance kmInstance to macroName
   setvariable "local_MacroGroupName" instance kmInstance to macroGroupName
end tell

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

-Chris

1 Like

Awesome!!

Ok, based off that, this version makes a group folder too. Let me know if you see any ways to improve it:

Found Image - Image to Path.kmmacros (56 KB)

Macro screenshot (click to expand/collapse)