Skip to content

Instantly share code, notes, and snippets.

@ruby0x1
Last active November 1, 2017 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruby0x1/970e61776666c3d109864b578bba8acf to your computer and use it in GitHub Desktop.
Save ruby0x1/970e61776666c3d109864b578bba8acf to your computer and use it in GitHub Desktop.
Running a bash script as a mac .app
#!/bin/bash
THIS_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# basically ./actual_binary but using a proper path
"${THIS_FOLDER}/actual_binary"
  • Consider a game.app with a game binary inside
  • Rename the binary file inside Contents/MacOS/game - let's say Contents/MacOS/thegame
  • Create a new empty file where the binary was Contents/MacOS/game
  • Put the example.sh bash code inside of it.
  • Change it to run thegame instead of actual_binary
  • make the new script executable with chmod +x Contents/MacOS/game
    • warning this permission can get stripped away on windows, zips, http etc.
  • That's it!

notes

The machination is: Info.plist has:

<key>CFBundleExecutable</key>
<string>game</string>

This tells the app what to run when double clicked.
Point it to a bash script that runs the game (and does other work ahead of that).

other notes

  • watch out for paths not being relative
  • watch out for modifying a code signed binary if doing mac app store
  • watch out for losing chmod +x permissions
  • it might be preferable to make an actual macos binary using a native compiled language to execute things like this to be water tight, but this should work in all cases outside of obscure ones.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment