Andy
Andy

Reputation: 11008

Can I make a macOS app made of Python script behave in the Dock like normal apps do?

The executable inside my.app/Contents/MacOS directory is a Python script (app.py) containing:

#!/usr/bin/python3
import os
from wsgiref.simple_server import make_server

with make_server(host=(host := '127.0.0.1'), port=(port := 1337),
                 app=lambda _, c: [c('200 OK', []), b'ok'][1:]) as s:
    os.system(f'open http://{host}:{port}')
    s.serve_forever()

When the app is started its icon begins to jump in the Dock for a long time and then jumping stops without getting the running indicator. So it looks like a stopped app that is pinned to the Dock while it's actually still running. It's impossible to move the icon in the Dock until it stops jumping. One can see the activity indicator if the app is pinned to the Dock.

enter image description here

Can I somehow communicate with macOS from the Python script to make it behave as normal apps do? E.g. using macOS Python with tkinter and the other pre-installed libs.

If you want to create the app yourself, you will also need the following my.app/Contents/Info.plist:

<?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>app.py</string>
</dict>
</plist>

Upvotes: 0

Views: 88

Answers (0)

Related Questions