I’ve made a little shell script + python tool on macOS that I want to be able to run from the dock. It works fine from the terminal.
I’ve followed guides I’ve found online to make a Bundle, which seems to be the most lightweight method to get a script in the Mac’s dock.
OpenRandomFile.app/ Contents/ MacOS OpenRandomFile
OpenRandomFile is a shell script with its executable permission set and starting with a zsh shebang.
The script captures a filename output from a Python script like so:
open -R "`/usr/bin/python ./randomfile.py`"
I’ve tried with the Python script
randomfile.py inside the bundle and outside in the filesystem, always using full paths.
When I run it from the bundle icon in the dock or elsewhere it opens a Finder window for the root drive, ignoring the Python script.
I’m new to macOS hacking so I don’t know how to debug this. It runs from the Terminal but I don’t want the dock version to open a terminal at all, which it doesn’t, but this means I can’t print debug strings from the shell script or the python. So I don’t know how to verify that the Python is executing at all.
I first suspected that some part didn’t have permission to access the directory, but macOS usually shows the user a dialog in this case. I now suspect it’s something to do with sandboxing, so I expected moving the Python script inside the Bundle would fix that.
So far I don’t have an info.plist file and I’m not 100% sure how to make one correctly. Would adding the Python script in the info.plist somehow register it as being officially part of the bundle?
There are very few questions about python scripts in macOs bundles so I ran out of luck with just Googling.
While I’m sure there are workarounds I’m sure it’s worth my time to learn about what’s possible or not in macOS bundles and how to set them up and debug them properly.
Source: Python Questions