0

I am trying to run a Python script from 'Automate the Boring Stuff' on MacOS by opening a .command file with Spotlight. I have been able to successfully run the script in Terminal by navigating to the directory containing the .py file and then entering: python3 mclip.py [keyword] , but when trying to run it with my mclip.command file, terminal opens a new window and displays this:

I'm not sure why it says no such file or directory, because that file definitely exists in said directory. Additionally, even if mclip.command did run successfully, how would I pass to it the [keyword] argument?

The contents of my mclip.command file are:

#!/usr/bin/env bash
python3 /path/to/my/pythonScript.py

and i'm attempting to run it by opening spotlight and typing in 'mclip.command'.

How can I make this work so that I don't have to navigate to the folder containing the .py file every time I want to run the script?

If you want more context, here are some links to the instructions I've been following: First is the instructions for the script itself is under Project: Multi-Clipboard Automatic Messages, and the instructions for creating and running the .command file are under Running Python Programs on MacOS.

Linus
  • 15
  • 2

1 Answers1

1

Once you have created your mclip.command file:

  • Go to the Terminal and type cd /your/folder/location/where/command/file/located/. This changes the current directory where the your command file is located.

  • Then type chmod u+x mclip.command. This will make your file executable.

Now you should be able to run your script on Spotlight. Either:

  • Press Cmd + space on your keyboard or clic on the magnifying glass on the upper-right corner.

  • type mclip.command (or just mclip and Spotlight will do the rest) and press enter.


I still have a problem though:

  • I am unable to pass arguments to my command file on Spotlight.

I would like to do something like, Go to Spotlight and type:

  • First mclip.command save <keyword> in order to save what is copied in the clipboard to the key.

  • Then mclip.command <keyword> in order to reuse what has previously been saved.

It seems to be very easy to do it on Windows (press Win-R and type mcb save <keyword>) but somehow it does not seem possible on Mac OS.

Or is it? I'd love to find a solution or at least a workaround to quickly execute scripts passing arguments directly on Spotlight...

Let us know if you have the answer =)

Flavinsh
  • 26
  • 2
  • I found a decent workaround [here](https://stackoverflow.com/questions/30854358/mac-osx-allow-for-user-input-in-shell-script-via-gui-or-prompt) from scottgwald. Basically you can edit the .command file and use the `read` command to accept user input and then pass that as an argument when you tell the .command file to run the code. – Linus Jul 02 '21 at 22:19