1

Say I have a hello.py file in /Users/jsmith. How can I easily run this script from Spotlight? Ideally, I'd like to save myself the trouble of opening a Terminal or Finder window to run it.

Do I have to place a #! /usr/bin/env python3 shebang line at the top? Does it have to be in a folder on the PATH environment variable? I need a way to quickly run a Python script with minimal fuss.

2

As this answer suggests, you can create a .command script that runs the Python script. For example, this should work:

#!/usr/bin/env bash
python /Users/jsmith/hello.py

Then, to run it you can just search for its filename, select it, and hit enter.

Remember that you'll have to make the .command file executable: chmod a+x hello.command (replace hello.command with the filename).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.