Please let me know how to run / invoke .dmg application in Java.
I used below syntax
Runtime.getruntime.exec("sample.dmg")
but it throws an error as "permission denied" with error code 13. Please let me know how to invoke dmg.
A DMG file is not directly executable. You need to use the Mac OSX open command:
Runtime.getRuntime().exec(new String[] { "/usr/bin/open", "sample.dmg" });
You may need to have the full path to the dmg file but otherwise it seems to work fine for me. Open also let's you specify the application to do the opening so you can do cool things like send this document in the Mail application as an attachment:
Runtime.getRuntime().exec(
new String[] { "/usr/bin/open", "-a", "Mail", "letter.pdf" });
I use open from the Mac command like this all of the time.
You should use Desktop.open(File file) which will use the appropriate opener for the OS. In your case on a Mac it will use open. This is better than Runtime.exec as you're not relying the exact location of the open command. Furthermore, this would even work on Windows if it had a DMG mounting application, such as Mediafour's MacDrive.
The bottom line is use Desktop.open(File file) to open a file with the operating system's default opener, that's what it's there for. Most people only use Runtime.exec as a last resort.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With