Can I run a Terminal Command via Shortcuts on MacOS?

I hate to sound like a Newbie but I can’t crack this.

I use a CLI tool called GAM to manage my Google Workspace domains and I’d like to build Shortcuts to run on my Mac that will collect some options, build a command and then run it in a Terminal window. However, I can’t figure out how to make this happen.

Can someone help this newbie out?

Without knowing exactly what it is you are trying to do and what exactly it is you are having trouble with, it is going to make it tough to give specifc advice.

For example if your issue was working with the Terminal app, maybe use of a shell script action might be an option?

If your issue is building the command, the documentation and what it is you want the commend to do would be necessary.

Yes, of course that makes sense. :slight_smile:

What I want to do is:

  1. Use Shortcuts to ask myself some questions and load up variables with the answers.
  2. Use those variables to output a single command in the Terminal.

I don’t have an issue with #1, only with #2: I can’t figure out how to actually output text to the Terminal command prompt.

For example, using GAM, I would use the following command to create a user:

gam create user firstname Clark lastname Kent password S0n0fKrypt0n

So my shortcut would collect the username, first name, last name and password values… then outputs the command to the Terminal command line.

Is that clearer?

If #2 is all you have trouble with, then look at the shell script action rather than how to interact with the terminal app.

The terminal app is running an interactive shell where you could provide input, whereas the shell action in Shortcuts will run a non-interactive shell, executing a sequence of one or more preset commands. Since you are doing all the interaction in Shortcuts and just need the command executed, that should be just fine for your needs.

1 Like

In case it helps I recently learned how to “inject” Shortcuts text into a terminal command, just right click on the text and add it from the list of variables

(you’d want to sanitize the data and surround the variable with quotes of course)