Quick Question on How to Best Use TextExpansion w/ Multi-Command Shell Functions

It's more specifically an Anaconda function being called through Terminal. But the snippet I'd like to bind to a string.
The desired output would be:

conda skeleton cran {package-name}
conda build r-{package-name}
conda install -c local r-{package-name}

I've read a few different circumstances where similar shell commands are invoked with precaution to maintain the sequence order as well as using a return key simulation to execute.

I'm wondering if there is way to do this where {package-name} is either prompted in the beginning or it's entered with the cursor in that position where I'd enter the specific package name. The following two lines use the exact same name and hence the curiosity if there's a way to do this, with automated execution, but also be able to enter a one time custom package name.

The most intuitive way to me, being not at all familiar with the full functionality of the KM, has been to set up a "User Input" --> Package_Name_Variable.

Then "Insert text by typing":

conda skeleton cran Package_Name_Variable && conda build r-Package_Name_Variable
Simulating Return:
conda install -c local r-Package_Name_Variable
Simulating Return

I think the first two command lines can be run together but I've only tested this a few times. Any ideas on maybe a more complete method of going about this?

Sorry for any repetition, as I know there're many similar Q&As but I didn't find anything that was specific to multiple line executions combined with repeated "Package Name" string. All help Appreciated.


I presume package name is something relatively short/simple, if so you have two choices, either a Prompt for User Input action or a regex Typed String trigger.

Usually, if the tool is well written, you can do them like:

conda skeleton cran PACKAGE && conda build r-PACKAGE && conda install -c local r-PACKAGE

And then each successive part will run only if the previous part succeeds.

So the action is simple, just Insert Text by Pasting action, with the preceding text, and a return at the end, using `%Variable%Package% instead of the package name.

Preceding that, you can use a Prompt for User Input action to prompt for the Package name, that is the easy and simply way. Alternatively, you can use a macro like this:

Example Terminal Command.kmmacros (1.9 KB)

Then you type =conda-PACKAGE= and Keyboard Maestro will replace it with the specified text (I don't have conda, so I just used echo to test, but the same process works easily enough).