Duplicating and Renaming a Macro With a Variable?

I'm setting up a Shortcuts workflow to build project templates. I'm having it populate my Dropbox with folders that are named with project name variables.

Basically it creates:

~/Dropbox/%Client%Project name%

and corresponding folders for communication with the client and my assistant.

Now I want to have these variables passed on to KM using %TriggerValue% – BUT – I would like to have KM make a project specific workspace.

Is it possible to have KM duplicate the '4 Finder' Macro and rename it with %TriggerValue% with a Shortcuts shortcut?

Hey Thomas,

It makes no sense to me that you're operating on Keyboard Maestro with Apple Shortcuts and trying to employ a KM TriggerValue in the process.

Perhaps you can describe your workflow in more detail...

-Chris

I'm confused -- if you are setting up a templated bunch of folders in the Finder, why do you need to duplicate and rename a KM macro?

If it's so that you can open folders in differently-named project structures, you can probably do that with only one macro that you pass the project name or location to and which then uses that as a variable.

I see it was vaguely described. Sorry.
I'm using KM conflict palettes for Finder window management. So basically every time I set up a project I would like to have a new macro in the palette with the project name (and hopefully also opening Finder windows to project paths).

Hope this makes sense.

Thanks,
Thomas

Do all these macros do the same things, just with different "base" directory and directory names for each project? If so, you might be better off having one macro that does "all the things" and your "project" macros call that with the appropriate parameters.

If you do want a macro for each then you could base an AppleScript on the following -- you can get the template macro's UUID from its AppleScript trigger and should be able to change the hard-coded values at the top of the script for some passed in from a previous Shortcuts action:

set newMacroName to "New Project Macro"
set projectName to "Project Number 3"
set projectBasePath to "~/Desktop/Project 3/"

tell application "Keyboard Maestro"
	set newMacro to item 1 of (duplicate macro id "E556A47F-ADF0-45C0-A080-4C7C66E3B741")
	set the name of newMacro to newMacroName
	
	-- Set the Project Name
	set AppleScript's text item delimiters to "TemplateProjectName"
	set theXML to every text item of (get xml of action 1 of newMacro)
	set AppleScript's text item delimiters to projectName
	set the xml of action 1 of newMacro to (theXML as text)
	
	-- Set the Project Name
	set AppleScript's text item delimiters to "TemplateBasePath"
	set theXML to every text item of (get xml of action 2 of newMacro)
	set AppleScript's text item delimiters to projectBasePath
	set the xml of action 2 of newMacro to (theXML as text)
end tell

Sample template you can use with the above (after you've changed the UUID to suit):

4 Finder Test.kmmacros (1.6 KB)

Macro image

...which will result in this new macro, in the same Macro Group folder as the template:

New macro image

1 Like

Thanks for the reply, Nige_S. I will need some time to process the information and figure it out :slight_smile: