uploading and redownloading executable script - macos

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".

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).

Related

How to build an installer for a python application for Mac

I have created a python application and can install it perfectly fine on Windows. I run pyinstaller to generate the executable, and then use NSIS to create an actual installer. I run the installer and it installs the application to my Program Files folder and gives me a nice desktop shortcut, etc.
What is the process to do the same for Mac? Essentially, I want to give my user a single file. When they run the file, it installs my program and any necessary libraries, and let's them launch it with a single click. I believe on Mac this is done with a .dmg or a .pkg file. What software/tools do I need to generate such a file? Do I need to restructure the project in anyway to create this?
For more info, pyinstaller creates a folder 'dist' which contains the unix executable of the application, and copies of python and any required libraries.
Note that I do not want to use the onefile option for pyinstaller because it would take a while to unpack everything each time the program is ran.

Run file when .tar.gz file is opened

I am trying to make an executable link in an email for mac, so I don't want it to be a .exe file. I tried using a .command file so that it will run when you click on it, but it said it's from an unidentified developer and I don't want the recipient to have to change their security settings. So I want to use a .tar.gz file that has a shell script in it.
The problem is that when you click the link, it downloads but doesn't automatically run the shell script. I need to know when the file is unzipped so I can run the shell script inside. Does anyone know how to do that?
It isn't reasonable to expect to be able to run an arbitrary script on user's machine, without him explicitly asking to run it (e.g. if all he's doing is downloading a file, or opening a non-executable file).
If the OS allowed that, it would be a serious security breach.

Proxy shell script as app bundle executable

I create an app bundle which has a shell script as main executable.
This then runs "exec /path/to/other/executable" as its last action.
(The reason for this is that I download new executables through an update system, and I don't want to write into the app bundle which typically is in /Applications. Instead I write updates to the user directory, and aim to let the app bundle itself be just a kind of launcher)
The problem is that this makes OS X think that the bundle directory is the one in which the second executable is. This causes it to not respect Info.plist, and all kinds of badness. (If I move the real executable into the MacOS folder of the bundle, everything is peachy, but as I said this is not really an option)
This guide led me to believe that something like this was possible:
http://mjhutchinson.com/journal/2010/01/24/creating_mac_app_bundle_for_gtk_app
Here they run "exec mono ..." as the last action in their shellscript, where "mono" is a binary residing outside of the app bundle somewhere. And I assume their bundles end up being well behaved.
Is this possible then?

Cocoa application won't run because Contents/MacOS/Application is not a Unix Executable

My application runs fine on my system, and also on several others.
However, some people can't run the application because the file in /Contents/MacOS/ApplicationName is not a Unix executable file.
Inputting the following line in the terminal forces the application to be executable, and solves the problem:
chmod +x ApplicationName
Obviously this is a very hacky way around the problem, and I don't want to tell users to enter chmod to run my application. What am I doing wrong? Why is it appearing as a Unix executable file on some systems, but not others? It could be a permissions issue...
at the moment, i transfer the app via dropbox to a client
Dropbox has problems with OS X metadata and permissions. Archive the application first (from the Finder context menu) and put the zip file into Dropbox.

Equivalent of double-clickable .sh and .bat on Mac?

I am distributing a Java program where I want a double-clickable file to run
java -cp MyProgram.jar;MyLib.jar my.program.Main
On Windows I simply distribute a .bat file, for *nix an executable .sh file. Problem is, double-clicking the .sh file just opens it up in a text editor on Mac. What should I do for Mac?
On mac, there is a specific extension for executing shell scripts by double clicking them: this is .command.
For Java applications on Mac, you really should use Apple's Jar Bundler (in the Developer Tools/Applications/Utilities folder; really a symlink to /usr/share/java/Tools/Jar Bundler). It lets you make a proper OS X double-clickable app, including setting preferences for e.g. using the Mac toolbar, JVM version, graphics system, OS X app metadata and classpath/resources.
You can use a .sh (Shell Script), after all MacOSX is Unix!
The answer about using the Jar Bundler tool is correct, but if you want to use a .sh file, make sure the unix permissions are set properly to something like 755 with CHMOD, and make sure the first line contains the path to a shell installed by default on Mac OS X. Also note that even with the +x bit set, it may still ask the user whether they want to open it or run it.

Resources