🐍 Run Python from Mac's Spotlight Search
I have a small Python app that I frequently run randomly throughout the day. I thought it would be nice to be able to quickly run the app from Spotlight search instead of Visual Code. After a little Googling, I found a few different Stack Overflow answers to solve this problem (mainly this one).
So, we're going to create a app.command
file that will:
- Show up and run from a Mac's Spotlight search
- Run when double clicked
Step 1: Create the app.command file
I'm creating the launcher .command file on my Desktop, but you can put it anywhere.
cd ~/Desktop
touch app.command
chmod u+x ~/Desktop/app.command
Step 2: Edit the app.command file
Add these 7 lines to the app.command
file to run the Python app.
#!/usr/bin/env bash
cd /path/to/app/file
# activate virtual environment if needed
while true; do
python app.py
done
Note: This script will loop running the Python app forever. To exit, just use ctrl+C
.