how to create drag and drop mac installer? - cocoa

I have made my java application's jar file and now want to create drag and drop installer for it.Also I want to know that how to create shortcut for Applications folder for the same purpose.
how can I do this?

Seth Willits' DMG Canvas is a great and easy way to create customized DMGs (with things like an Applications folder shortcut, background image, etc). Yes, you can do this all yourself with hdiutil and whatnot, but I much prefer using a GUI.

You can Package your .jar into a .app (inside a dmg that has drag&drop) with Javapackager like this:
javapackager -deploy \
-title "YourTitle" \
-name "Name" \
-appclass your.class.start \
-native dmg \
-outdir ~/Downloads \
-outfile yourOutFileWithoutExtension \
-srcdir "SourceDir"
you could use -srcfiles Your.jar if its only a single jar.

Use either Disk Utility or the hdiutil command-line tool. It's easier to integrate hdiutil into an automatic build workflow.

You need to create a small disk image containing your application and a symbolic link to the Applications folder. Use Disk Utility or hdiutil to create the image. You can just copy the application in, and create the symbolic link using Terminal:
cd /Volumes/DiskImageName
ln -s /Applications Applications

Related

Alternatives to Platypus (which builds a mac .app that runs a script when user double clicks it), which run on Linux?

I already have software which runs on mac, which can be driven by a main 'runner' script. However, I want the software to be packaged as a .app. On a mac, I can run 'platypus' (https://www.sveinbjorn.org/platypus), and it will create a very nice .app file, which calls that runner script as an entry point (exactly what I am trying to do). It's very simple to use.
The problem is, platypus itself only runs on mac, and I need to bundle this all together (create the .app), on a Linux machine.
Is there an alternative to Platypus, which accomplishes the same result (generates a .app, with a script as the entrypoint), but which you can build on Linux? Or, is anyone aware of up-to date tutorial which explains how to accomplish this manually (but on Linux)?
(I've seen this: How to build a dmg Mac OS X file (on a non-Mac platform)? but it is for dmg files, while I need a .app file. Also, I'm specifically curious about programs simple like Platypus is.)
A mac .app "file" is actually just a folder (you can browse the contents by right clicking, "show package contents".
The main part you'd need to change is the .sh script itself which can be found within the app package: yourapp.app/Contents/MacOS/yourscript.sh
So you could copy an existing yourapp.app and use it as a template, just editing the script contents and app (folder) name all within Linux.
You might have to set permissions when copying back (chmod +x etc.).. I'm not sure having not tested this method, but I can't see why it wouldn't work.
Adding some reference code (bash), on top of BSUK answer:
mkdir -p foo.app/Contents/MacOS
cp foo.sh foo.app/Contents/MacOS/foo
chmod +x foo.app/Contents/MacOS/foo
It's also possible to set a nice icon for the app, with the following reference code:
(please prepare in advance a logo.png file, and its corresponding icon.icns version):
mkdir -p foo.app/Contents/Resources
cp icon.icns foo.app/Contents/Resources/
cp logo.png ./
sips -i logo.png
DeRez -only icns logo.png > tmpicns.rsrc
Rez -append tmpicns.rsrc -o file.ext
SetFile -a C file.ext
cp -f file.ext foo.app/Icon$'\r'
rm tmpicns.rsrc logo.png file.ext
SetFile -a C foo.app
You may then allocate that foo.app on your desktop (for example) with:
mv foo.app "/Users/$(whoami)/Desktop/"

Error creating disk image using hdutil

I'm trying to build dmg of .app file using following hdutil command:
hdiutil create -srcfolder /Users/me/My.app My.dmg
It works as expected as it creates My.dmg correctly. Problem started happening when I add two more files in to .app bundle before calling that hdutil command. The hdutil ends up with error:
diskimages-helper: resize request is above maximum size allowed.
hdiutil: create failed - Invalid argument
Thanks for any help you can provide.
I had the same problem. The solution I found at Apple Support Communities worked for me. I ended up adding an empty .Trash file into the folder before calling hdiutil:
touch root_folder/.Trash
or with Ant in my case:
<touch file="root_folder/.Trash"/>
You can optionally specify a '-size' parameter when you invoke hdiutil. If you specify a size large enough that the disk image doesn't need to be resized during .dmg creation, it seems you can avoid this error.
E.g.:
hdiutil create -size 240m -fs HFS+ -srcfolder test -volname Test test.dmg
I make images of folders like this:
hdiutil makehybrid -hfs -o output/path.dmg -hfs-openfolder input/path input/path

Porting PackageMaker command line build installer to pkgbuild

I've been attempting to port a Mac PackageMaker command line build to pkgbuild and productbuild but I'm stuck. Unfortunately I haven't found much of anything documenting how these new programs work except for this StackOverflow post and the pkgbuild and productbuild man pages.
Here's my problem. I've created a root install directory that has the following files in it:
/some_path/Applications
/MyProgram.app
/Library
/Frameworks
/MyFramework.framework
/[library files...]
The command line call below worked great for PackageMaker. It created an installer that installed all of the files above.
$ /Developer/usr/bin/packagemaker \
--title "My Program" \
--root /some_path \
--version 1.0.0 \
--filter "\.DS_Store" \
--resources ./resources/ \
--scripts ./scripts/ \
--root-volume-only \
--domain system \
--verbose \
--no-relocate \
--target 10.5 \
--id com.my_company.pkg \
--out MyProgram.pkg
Now I'm trying to write this with pkgbuild and having a major problem. I use the following call:
$ pkgbuild \
--root /some_path \
--version 1.0.0 \
--install-location "/" \
--scripts "./scripts/" \
--identifier "com.my_company.pkg" \
MyProgram.pkg
This command builds an installer that copies the MyProgram.framework directory into /Library/Frameworks. However it does not install the MyProgram.app file into the /Applications directory. When I look at the installer logs I see this message:
Applications/MyProgram.app relocated to
/some_path/Applications/MyProgram.app
Can anyone shed some light on why this isn't adding the MyProgram.app file into the /Applications directory like PackageMaker was doing?
Unfortunately the answer to this question wasn't exactly what I was looking for. I couldn't figure out how to eliminate PackageMaker from the process. However there is a solution that includes pkgutil along with PackageMaker to create an installer with custom welcome message, license and background image entirely on the command line. The PackageMaker GUI is NOT required. The steps are as follows:
Run the packagemaker command line executable on the special directory structure. This directory structure reflects the Mac file system. Read more in the old but reliable "PackageMaker How-to" tutorial.
Run pkgutil (pkgutil --expand) to extract the package contents
Take a look at the contents and identify what you want to alter. Some options are the welcome message, license and background image.
Add commands to alter these files via the command line. Review the "Automating Apple's PackageMaker" tutorial for more information. The easiest way is just to run something like this echo '<background file="your_background.png">'.
Run pkgutil (pkgutil --flatten) to rebuild the package.
First of all, are you sure that you need an installer? You could put the framework inside the application. The Installer and pkgbuild are a bit flaky, to say the least.
Now to the problem at hand: Relocation has to do with the fact that a user could move the Application from /Applications to say /WorkApplications /PrivateApplications. In your case the Installer probably finds your Application in the build folder and installs it over this one.
I think the Installer uses the Application Bundle Identifier and Spotlight for the relocation, so for testing you could add the build folder to the Spotlight ignore list.
You can define in the Component Property List BundleIsRelocatable. If you really have to install a framework global, this is one bundle where you want to set BundleIsRelocatable to false.
The question you reference has pretty much everything you need to eliminate Package Maker entirely. One thing I added is to use sed after the productbuild --synthesize ... invocation to insert lines into the distribution file. For example, here are some Terminal commands I use once I've already built the component package:
productbuild --synthesize --package "components/SubPackage.pkg" "distribution.xml"
sed -i "" \
-e '$ i\
\ <title>Installer Title</title>' \
-e '$ i\
\ <background file="background.png" alignment="left" scaling="proportional" />' \
-e '$ i\
\ <welcome file="welcome.rtf" />' \
"distribution.xml"
productbuild --distribution "distribution.xml" --resources "resources/" --package-path "components/" "Installer.pkg"
This avoids having to use pkgutil --expand and pkgutil --flatten to modify the installer.
Create component plist file, which has value for relocatable property.
pkgbuild --analyze --root "$dst_src_root" "$installer_root/Components.plist"
Edit component plist and Set "BundleIsRelocatable" to false.
This is done one time in my project, as installer contents does not change (One application and one plugin). I am reusing same component plist everytime to create contents package.
sudo pkgbuild --root "$dst_src_root" --component-plist "$installer_root/Components.plist" --identifier "com.company.app" --version "1.0" --scripts "$dst_scpt_root" "$dst_pkg_root/InstallPackage/cisContents.pkg"
Then using productbuild, we can create final package

How I make a dmg installer that will automatically open after download?

I have seen some dmg's which not only mounts after download but also copies the installer in the download folder and open the installer in Installer Application.
I don't know how to do it?
Can anyone help?
I haven't seen automatically opening dmg files, but it's possible to make folder open automatically after user mounts the dmg file.
Once you have created the dmg file, mount it and then issue following command:
bless --folder /Volumes/NAME --openfolder /Volumes/DIRECTORY
The NAME is your the mounted folder name and DIRECTORY is the directory that you wish to open automatically, often NAME and DIRECTORY are the same.
the --folder option is not necessary if just want the dmg to open the finder folder window automatically once mounted
bless /Volumes/NAME --openfolder /Volumes/DIRECTORY
The NAME is the mounted folder name and DIRECTORY is the directory that you wish to open automatically, often NAME and DIRECTORY are the same.
DropDMG works great for me:
http://c-command.com/dropdmg/
I don't know how to achieve this otherwise (free alternative / manually).
Script that will do this for you:
https://github.com/andreyvit/create-dmg
Example:
#!/bin/sh
test -f Application-Installer.dmg && rm Application-Installer.dmg
create-dmg \
--volname "Application Installer" \
--volicon "application\_icon.icns" \
--background "installer\_background.png" \
--window-pos 200 120 \
--window-size 800 400 \
--icon-size 100 \
--icon "Application.app" 200 190 \
--hide-extension "Application.app" \
--app-drop-link 600 185 \
"Application-Installer.dmg" \
"source_folder/"

Creating a .DMG

I want to create a dmg file for my Mac project. Can someone please tell me how to do this? This being my first Mac project, I do not have any idea how to proceed. I also want to give the user an option of running the app on start-up. How do I do this?
Thanks.
P.S. I also want to add a custom license agreement.
To do this manually:
Method 1:
Make a folder with the files your DMG will contain.
Open Disk Utility (It's in /Applications/Utilities/)
Go to File > New > New Image from Folder (Cmd + Shift + N)
Choose the folder containing you files
Make sure "Compressed" is checked, then set where you want to save the created DMG
Method 2:
To do things like setting a background image can be a bit convoluted (You basically add the background image to the DMG, set the windows properties to use that image, using the command line you move the background image from background.png to .background.png to make it hidden)
I would recommend iDMG, which makes things a bit less tedious.
You can also script the creation of DMGs using the command hdiutil. Something along the lines of
hdiutil create -srcfolder mydirtodmg mydmg.dmg
As for the custom license agreement, you should look into the tool included with the Developer Tools "PackageMaker" - it's pretty self-explanatory. It's in /Developers/Application/Utilities/
If you need to add a custom EULA to your disk image, this page describes how to do so using command-line tools. The gist of it is to use the template software licensing agreement resource provided in Apple's slas_for_udifs_1.0.dmg, modify the resource with your EULA text and inject the resource back into your disk image file. (I include brief instructions below in case the above link becomes unavailable, and to update the search term it provides in step 1.)
Using your Apple Developer account go to the Downloads page and search for Software Licensing for UDIF
Download and mount the disk image
In Terminal:
cd /Volumes/SLAs_for_UDIFs_1.0
DeRez SLAResources > /tmp/sla.r
Edit /tmp/sla.r in a text editor, updating the content of the data 'TEXT' (5000, "English SLA") resource to contain your new license text.
Unflatten the disk image file that contains your installer:
hdiutil unflatten installer_image.dmg
Add the edited license resources to the image:
Rez -a /tmp/sla.r -o installer_image.dmg
why don't you just run a script from your xcode project. try something like this:
# be sure to check the man page for hdiutil
# it is very powerful and has tons of options...
hdiutil create -megabytes 54 -fs HFS+ -volname awesome_app_install myAwesomeApplication.dmg
hdiutil mount myAwesomeApplication.dmg
cp -r /build/Release/AwesomeApplication.app /Volumes/awesome_app_install/
then save your script as something like 'makeDMG.sh' and in your target,
select add->new build phase->run script build phase
and drag your script into this build phase.
once you've done all that, then when you build your project the script will create the disk image and copy your release build into it...
of course you should spice your script to flavor... these three lines are just the raw meat
ps: your custom EULA should get built into your packagemaker project (which you can also script very nicely)
I made a little bash script to automate a disc image creation.
It creates a temporary directory to store all needed files then export it in a new DMG file. Temporary directory is then deleted.
You can automatically launch this script at the end of your build process.
#!/bin/bash
# Create .dmg file for macOS
# Adapt these variables to your needs
APP_VERS="1.0"
DMG_NAME="MyApp_v${APP_VERS}_macos"
OUTPUT_DMG_DIR="path_to_output_dmg_file"
APP_FILE="path_to_my_app/MyApp.app"
OTHER_FILES_TO_INCLUDE="path_to_other_files"
# The directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# The temp directory used, within $DIR
WORK_DIR=`mktemp -d "${DIR}/tmp"`
# Check if tmp dir was created
if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then
echo "Could not create temp dir"
exit 1
fi
# Function to deletes the temp directory
function cleanup {
rm -rf "${WORK_DIR}"
#echo "Deleted temp working directory ${WORK_DIR}"
}
# Register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
# Copy application on temp dir
cp -R "${APP_FILE}" "${WORK_DIR}"
# Copy other files without hidden files
rsync -a --exclude=".*" "${OTHER_FILES_TO_INCLUDE}" "${WORK_DIR}"
# Create .dmg
hdiutil create -volname "${DMG_NAME}" -srcfolder "${WORK_DIR}" -ov -format UDZO "${OUTPUT_DMG_DIR}/${DMG_NAME}.dmg"

Resources