How to resize and delete an image on Mac? - macos

I am following a guide to convert a .app file to .iso file on my Mac. I had to create an image and i typed the following line on my terminal
hdiutil create -o /tmp/Mojave -size 8500m -volname Mojave -layout SPUD -fs HFS+J
Since there was no enough space on this image I created another and another and now I'm full of created images on my PC.
I would like to know if there is any way to resize an image from the terminal. Moreover i would like to delete all the useless images that I created

Try this
1. In Finder, open up your Macintosh HD folder
2. Press CMD+Shift+Dot //this will show your hidden files
Then navigate to /tmp/Mojave and delete the files you just created earlier.
Repeat step 2 to hide them again!

Related

OSX One-step converting from ZIP to DMG via terminal?

Is there an elegant way of converting ZIP files to DMG?
I would avoid to expand the (many) files manually and then to repack'em to a DMG.
Could that be done via terminal, maybe in a single step?
There is an app called DropDMG that lets you convert between file types. The description on the website claims you go from .zip to a dmg file. The app is not free but they have a free trail available that may work for you.
A terminal command that might work is hdiutil.
hdiutil create -format UDZO -srcfolder folder_to_compress archive_name.dmg
I just tried this on a .zip file and it worked. But note that when I launch the .dmg file I just get the .zip file back.
You could also write a two line script. First line is to unzip the zip file and then use the hdiutil command to make a dmg from the expanded files.

Error while using setfile to set icon for dmg created via hdiutil in mac

I have created an app & signed using "Developer ID Application: x" certificate.
then using hdiutil i created the dmg
hdiutil create -size 1.5m -format UDRW myapp.dmg -srcfolder ./myapp/ -fs HFS+
to set the drive icons when i execute the below commandsit throws the error
# custom drive volume icon..
#cp drive_icon.icns /Volumes/myapp/.VolumeIcon.icns
#SetFile -c icnC /Volumes/myapp/.VolumeIcon.icns //(throws error -5000)
dev:Unexpected error. (-5000) on file: /Volumes/myapp/.VolumeIcon.icns
I thought it would be related to size and increased the size of dmg from 1.5m to 4.5m but that also not helps, image size is 291kb and the overall app size is 666kb.
I created the .app in build machine (mac 10.10 xcode6.2), and tried creating this hdutil in our codesigning server (mac 10.11).
can anyone tell me where it went wrong.
In the man page I see setfile is deprecated is there any other equivalent command to do
Thanks and Regards,
Saravana
found another way to set icon.
Right click the DMG file and click "GetInfo"
Drag and drop the icon file to the icon location present in the GetInfo dialog box.
it sets.
Thanks and regards,
Saravana

Make link to Application folder

Sublime Text editor has in DMG file link to Applications dir (blue icons with arrow). It has small size.
How to make such link on my own folder? It must work in all Macs.
Open the terminal, use cd to open the folder where you want to create the symbolic link (this is how that kind of link is called, in case you want to research a bit more about it). Example:
cd /Users/MyUser/Desktop/
Note: In case the path has spaces, write it with backslashes before each space, like that:
cd /Users/MyUser/Desktop/My\ Folder/
Then, use that command to create it:
ln -s /Applications/ Applications
It will create a symbolic link which opens the path /Applications/, which means that it will work in any macOS computer.
Reference:
https://apple.stackexchange.com/a/115648

Shell/ Bash Nested loop – Automator Folder Action

How can I automate the process of saving an SVG in multiple resolutions or file formats? Without the need to open any application such as Illustrator? Also how can I generate a retina ready fallback versions of that SVG?
Use the Node.js module svgexport (download) and Automator on Mac OS!
Installation
First install svg export globally using terminal (“npm” must be installed):
npm install svgexport -g
Automator
Create three folders e.g. on your desktop for convenient use: “convert”, “png”, “svg” (In this example we only generate pngs from the svg, but jpg, pdf or else work, too)
Open Automator & create a new folder action (CMD + N). Open & select the just created folder “convert”.
Add a “Shell-Script” action from the library
Set Shell to “/bin/bash” and “Pass Input” to “as arguments”.
The Script —
Now let’s add the code and afterwards save the Automator action.
PATH=/usr/local/bin:/bin export PATH
for i in "$#"; do
for size in 100 250 640 1024 1600 2000; do
o="${i%.svg}_$size.png"
o2x="${i%.svg}_$size#2x.png"
svgexport "$i" "$o" png 100% $size:
svgexport "$i" "$o2x" png 100% "$(($size*2))":
mv "$o" ~/Desktop/png/
mv "$o2x" ~/Desktop/png/
done
mv "$i" ~/Desktop/svg/
done
Test:
Now grab a svg, drop it in the convert folder and see the magic happen.
Explanation:
We have two for loops: The first running for each file added to the svg folder, the second creates two versions for each size as listed. One normal and one retina (#2x). We rename the files and add the size to each filename. Finally we move the generated images to png folder and the source svg to the svg folder.
Here is a great article that explains the above code in more detail

Extract from DMG

How to extract content of DMG without mounting it?
I want add autoupdate system to my application. It downloads DMG from website, then extract new version of application from it.
Some .dmg files can be extracted by using 7-zip.
$ 7z x your.dmg
$ ls
your.dmg
0.MBR
1.Primary GPT Header
2.Primary GPT Table
3.free
4.hfs
5.free
6.Backup GPT Table
7.Backup GPT Header
...and after extracted the 4.hfs file:
$ 7z x 4.hfs
...you'll get the content of the .dmg file.
You could also mount the .dmg in Mac OS X using hdiutil command (which is also used by Homebrew Cask).
Please refer to this Ask Ubuntu question for more use cases on Linux.
Dmg is just a format used for MacOS. It's a not compressed file format like zip or tar.gz
You have several choices to mount it. Here are some options.
Double click on it to mount it.
Use hdiutil attach your.dmg to mount the dmg file. After mounting on it,
operating your command line to extract the files you want out.
Doing that is working counter to the design of DMGs, so it's very painful. DMGs are designed to be mounted, that is their whole raison d'être. You would need to rely on experimental code if you wanted to do something like that. You are probably better served by using a non-DMG archive such as a zip file, or by making your automatic updating process download, mount, and unmount the DMG file you provide.

Resources