Vikas Bansal
Vikas Bansal

Reputation: 11740

How to create .dmg of a folder from objective-c or terminal?

Scenario

I need to convert a folder to .dmg using objective-c however, I am not able find any script in obj-c that is why I am looking for a terminal command that can do this.

Research

I am using the given below terminal command in order to convert a folder to .dmg

hdiutil create -format UDZO -srcfolder 
"/Users/Paxcel/Desktop/IMG" 
"/Users/Paxcel/Desktop/IMG.dmg"

Problem

The above command is not working and giving no result as shown in the screenshot given below: enter image description here

Please suggest a solution that can help me create a .dmg file of a folder. Many thanks for your attention.

P.S: I have to use either obj-c or terminal because I am creating an utility in cocoa app.

Upvotes: 1

Views: 489

Answers (2)

Vikas Bansal
Vikas Bansal

Reputation: 11740

Using " was a mistake. I am from windows world and there (in windows) you always have to put a path into quotes "c://test.txt"

Earlier (Wrong)

hdiutil create -format UDZO -srcfolder 
"/Users/Paxcel/Desktop/IMG" 
"/Users/Paxcel/Desktop/IMG.dmg"

Correct

hdiutil create -format UDZO -srcfolder 
/Users/Paxcel/Desktop/IMG
/Users/Paxcel/Desktop/IMG.dmg

However if you path contains spaces then if you use quotes then it will give an error like given below enter image description here

Resolution In order to escape the error you must use '\' before spaces ' ' as given below:

hdiutil create -format UDZO -srcfolder 
/Users/Paxcel/Desktop/IMG\ for\ design
/Users/Paxcel/Desktop/IMG\ for\ design.dmg

I have run both commands and the result is shown in the screen shot given below Quoted path is not working but using '\' in path is working like a charm enter image description here

Upvotes: 2

Droppy
Droppy

Reputation: 9721

You have a stray " in your command line.

The > prompt means more please; the shell wants you to terminate the ".

Upvotes: 1

Related Questions