Skip to content
Advertisement

How can execute a shell script from spotlight on macOS passing a first command line argument?

I have written a python program that needs a first command line argument to run from the Terminal. The program can be used to copy a text to the clipboard when it is run with a certain keyword.

JavaScript

This use case is just an exercise to understand, how I can run a batch file on macOS (or shell script in macOS terminology).

I have created the following shell script and saved it as mclip.command:

JavaScript

My idea is to execute my shell script from the spotlight input window, passing the argument ‘agree’. How can I do that?

On windows the batch file would look like that (mclip.bat):

JavaScript

I can press WIN-R and type mclip *argument* to run the program. But how can I do the same on a Mac? I cannot type mclip agree in spotlight, that doesn’t work like in WIN-R.

JavaScript

Advertisement

Answer

Assume the shell script (mapIt.command) is:

JavaScript

The $@ is interpreted as a list of command line arguments.

I can run the shell script in the MacOS Terminal like that:

JavaScript

The command line arguments Streetname Number City are forwarded to the python script.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement