Search code examples
javamacosmountdmg

How to open mounted disk on mac through java program?


I am downloading a dmg file and then trying to open up the installer automatically through java code.

I am able to download the file and then mount it using "hdiutil attach file.dmg".

Download file using URL , Input stream and Output stream

Mount dmg by: /usr/bin/hdiutil attach file.dmg

I am unable to open up this mounted disk so that the installer comes on foreground. Any thoughts on how this can be done?

Thanks!

Harsha P


Solution

  • execute open /Volumes/VolumeName and it'll open the finder folder for it

    or run an applescript using osascript to bring the finder to foreground explicitly if needed:

    property the_path : "/Volumes/MyMacDrive/Mani/WorkSpace/" set the_folder to (POSIX file the_path) as alias tell application "Finder" activate if window 1 exists then set target of window 1 to the_folder else reveal the_folder end if end tell