views:

49

answers:

2

How can I download and open a .dmg file using cocoa or applescript

+3  A: 

Try NSURLDownload or NSURLConnection. Google also answers the question handily if you leave out the "dmg" part and go more generic.

Joshua Nozzi
well the big thing is is that it has to open the DMG file
Matt S.
When the file is done, ask the shared NSWorkspace to -openFile: ...
Joshua Nozzi
Matt S.: Downloading a file and opening a file are separate tasks with separate solutions.
Peter Hosey
A: 

As @Joshua said, you can use NSURLDownload or NSURLConnection to retrieve the file. To mount it, run an NSTask that executes hdiutil attach /path/to/downloaded/file.dmg.

Dave DeLong
Ouch. Seems a bit heavy-handed. Is there some advantage to using hdiutil versus opening the file with NSWorkspace?
Joshua Nozzi
A quick test shows that, where UI is needed (the case of a password-protected dmg), you'd need to interact with the task to supply the password. Via NSWorkspace, you're prompted in the GUI as when opening with Finder.
Joshua Nozzi