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

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

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

mkdir/cp in Mac terminal gives "Permission denied" error

I'm trying to copy a directory in terminal from the Downloads directory to a sub-directory within the Applications/ directory, and I keep getting "Permission denied" error. Why is this so?
try
ls -lt
to see access permission of the folder you want copy file into
then use
chmod 777 your_folder_name
to change the access permissions of the folder
If you "right-click -> Get info" the Applications folder you will notice that the permissions for the Applications folder are Read/Write for 'system' or 'admin'. For 'everyone' it's Read-only. If you are not an admin you need to use 'sudo cp -R Downloads/___Test /Applications'. Obviously, you need to enter a password.
MacOS prevents interaction with downloaded files until you confirm that they are safe. You can effectively do this programmatically by running:
xattr -d com.apple.quarantine ~/Downloads/your_file_here
Then you should be able to copy the file.

Backup to external HDD with terminal commands

Is there any terminal command that allows me to backup all my files to an external HDD. My OSX update failed so I need to backup my files some how, ASAP!
I would go with rsync as it only copies files changed since the last time you ran it, making it quicker on second and subsequent backups.
Assuming your username is Freddy Frog and your external HDD is called My External Drive, you could do this:
rsync -av "/Users/Freddy Frog" "/Volumes/My External Drive"
cp -R /Path-to-folder /Path-to-external-HDD
This wil copy the folder from (Path-to-folder) to the external HDD
If you want to make this an recurring command, the are a few steps to be made:
Open texteditor and write:
http://pastebin.com/fNuCMMr4
Save it as Backup.plist
Now navigate to /Library/LaunchDaemons and place the file in the folder
Restart your machine
Every day at 15:00 the folder of /Path-to-folder will be copied to the external HDD (if the mac is running at that time)
And yes, ofcourse you need to modify the code I gave you for the .plist file
backup to a single (optionally compressed) disk image file that can be restored using Appleā€™s Disk Utility software with hdiutil
sudo hdiutil create dst_image.dmg -format UDZO -nocrossdev -srcdir src_directory
OSXDaily also provided examples in 2009: for ditto, rsync, & asr
sudo ditto -X src_directory dst_directory
sudo rsync -xrlptgoEv --progress --delete src_directory dst_directory
sudo asr -source src_directory -target dst_directory -erase -noprompt
With new macs which use AFS (Apple file system), do:
diskutil list
to get a list of disks and their identifiers. Then, unlock your disk with:
diskutil apfs unlock <disk_identifier>
and provide your password. You should now view your disk under /Volumes/. For me, the disk of interest was Macintosh HD - Data.

how to create drag and drop mac installer?

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

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