Domanda

I have an executable terminal program (built on MacOS from Haskell code with GHC) which runs when I double-click it in the Finder. I want to put this on my website, from which people can download and run it from their Finder by double-clicking.

Somehow in this exchange the file loses the "+x" bit so that when it's re-downloaded it can't be run by double-clicking anymore. I can still run it but I have to do "chmod +x" first. What can I do so that the downloaded file will be executable by default? Do I have to package it inside a ".app" file? Right now it's ".command".

È stato utile?

Soluzione

Regardless of whether it's part of an app bundle, the executable itself needs to be… executable. To ensure executability, you should put it in a zip or dmg file, which will preserve its 'executable' flag.


If you want to make it into an app bundle, there's a simple way to do that. If the executable is named PROGRAMNAME, then just put it in a folder called PROGRAMNAME.app. Double-clicking should run the file.

If you want to create a more proper app bundle, use this:

APP_NAME='My Awesome App.app'
EXE_NAME='PROGRAMNAME'

mkdir -p "$APP_NAME"/Contents
defaults write "`pwd`"/"$APP_NAME"/Contents/Info CFBundleExecutable "$EXE_NAME"
mkdir "$APP_NAME"/Contents/MacOS
cp "$EXE_NAME" "$APP_NAME"/Contents/MacOS
chmod a+x "$APP_NAME"/Contents/MacOS/"$EXE_NAME"

App bundles will not display Terminal output or report errors, so if you need that you should keep it as a raw executable. Also, simple apps made in the above manner will not have a GUI and will appear to not respond and will exit when they finish running.

Also, if you get the following message, it might be because the executable is too short (add more characters to it) or because of quarantining restrictions (try editing the executable and save it with an app like TextEdit to make it trusted).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top