To run a Python script from macOS's Application folder and via Spotlight , you need to wrap your Python script in a macOS application bundle (.app). This makes it appear as a native macOS app, which can be launched like any other app — from the Applications folder, Spotlight, Dock, etc.
✅ Step-by-Step Guide: Turn Your Python Script into an App
1. Create the Folder Structure
Create a folder for your app with this structure:
code Copy code
MyPythonApp.app/
└── Contents/
├── Info.plist
└── MacOS/
└── myscript.py
You can create it manually or via Terminal:
bash Copy code
mkdir -p MyPythonApp.app/Contents/MacOS
Place your Python script (myscript.py) inside MyPythonApp.app/Contents/MacOS/.
2. Create Info.plist File
This is the configuration file that tells macOS how to run your app.
Put this inside MyPythonApp.app/Contents/Info.plist:
xml Copy code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>myscript.py</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourname.mypythonapp</string>
<key>CFBundleName</key>
<string>MyPythonApp</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
</dict>
</plist>
You can customize CFBundleName, CFBundleIdentifier, etc., as needed.
3. Make the Script Executable
At the top of your Python script (myscript.py), add the shebang line:
python Copy code
#!/usr/bin/env python3
Then make the script executable:
bash Copy code
chmod +x MyPythonApp.app/Contents/MacOS/myscript.py
4. Move the App to the Applications Folder
Drag MyPythonApp.app into your /Applications folder.
Alternatively, use Terminal:
bash Copy code
mv MyPythonApp.app /Applications/
5. Launch via Spotlight or Applications Folder
Now you can:
Open Spotlight (Cmd + Space) and type MyPythonApp.
Navigate to /Applications and double-click the app.
It will run your Python script as if it were a native app!
📦 Optional: Bundle Python Environment (Advanced)
If your script uses external libraries or needs to be portable:
Use tools like PyInstaller , cx_Freeze , or py2app .
These package Python + dependencies into a standalone .app.
Example using PyInstaller :
bash Copy code
pip install pyinstaller
pyinstaller --onefile --windowed myscript.py
This creates a macOS .app in the dist/ folder.
🔍 Troubleshooting Tips
If nothing happens when launching the app, check Console.app for logs.
Make sure your script doesn't rely on a terminal environment unless you include one.
To test your app bundle quickly, right-click → Open (especially if macOS blocks unsigned apps).
Let me know if you'd like help writing a full .app bundle generator script!