How create dynamic (growable) DMG file using terminal in MacOS - macos

I want to create dynamic (growable) dmg file. I know sparse bundle works well with dynamic file but i want to create blank dynamic dmg file. I tried the following but did not work. Can anyone help please!:

Create a Sparse Image (.sparseimage) rather than a Sparse Bundle (.sparsebundle).
$ hdiutil create -size <size> -type SPARSE -fs HFS+ <name>
So to create MyDMG.sparseimage that would hold a maximum of 100 MB you would do:
$ hdiutil create -size 100m -type SPARSE -fs HFS+ MyDMG
Additional Information:
↳ https://apple.stackexchange.com/q/5751/10139

Related

Set icon to dmg file not working with icns and png

I am creating a dmg file and getting following error while using the icns and png files..
Here is the command:
DeRez -only icns resources/test.icns > icns.rsrc
Error:
/Applications/Xcode.app/Contents/Developer/usr/bin/DeRez - SysError
-39 during open of resource file "resources/test.icns"
Mac OS version: macOS mojave 10.14.2
Please suggest.
Encountered this just now as well and noticed this question has gone unanswered, even though it's fairly simple.
Apparently error -39 means end of file, I'm assuming this means it wasn't able to find a valid portion of expected data. I'm guessing you (like myself) used sips -i someicon.icns to set the file's icon to itself? You should've gotten an error --addIcon is no longer supported which to me means that it didn't actually set the icon. So a subsequent DeRez call to get a .rsrc out of it will fail.
I didn't want to install any extra stuff but luckily I found another answer on here that seems to use only standard Xcode and/or macOS tools. In my case I was trying to set an AppleScript-exported .app icon, but the actual conversion part should be the same regardless.
So, all the steps to go from .png to an actual icon for an .app file:
cd /some/application/dir/some.app/Contents/Resources
cp /some/assets/dir/myicon.png ./
# Convert png to icns
# Keep in mind that sips can allegedly only handle 256x256, 512x512 and 1024x1024 PNGs for this
# Otherwise you need to do something like the following first:
# sips -z 256 256 myicon.png --out myicon_resized.png
# Then check if it came out good and run:
# mv -f myicon_resized.png myicon.png
# Now let's actually convert it and remove the png as it's no longer needed
sips -s format icns myicon.png --out myicon.icns
rm -fv myicon.png
# Apparently you can also specify commands of some sort in .rsrc files (this is the part I needed from the other SO answer)
# This is used in place of DeRez
echo "read 'icns' (-16455) \"myicon.icns\";" > myicon.rsrc
# Now just use Rez to append it to the special icon file in the root of the .app dir
Rez -append myicon.rsrc -o $'../../Icon\r'
# Write the metadata indicating we want to use the Icon\r file for the app's icon
# I could just use ../../ for the path but I like to be explicit
SetFile -a C ../../../some.app
# Also hide said file from Finder views
SetFile -a V $'../../Icon\r'
I haven't tried setting custom icons for a .dmg file, but I guess you already know how to "apply" the .rsrc to it anyways. =]

Convert a PDF to Images using sips

I want to convert a pdf with several pages to single image files using sips. I know there are several other (probably better) solutions to do this but sips is installed on every mac and don't need a licence.
What I tried:
sips -s format png myPDF.pdf --out myIMG.png
That gives me an image of the first site from the pdf.
Now my Question: Is there a possibility to get images for each page of the pdf?
Thanks for your advise!
I have no idea whether you are supposed to do this sort of thing this way, but the Automator on macOS has an action called Split PDF which you could use to split a PDF into separate pages and then use sips on each one...
To start Automator, press ⌘space and start typing Automator till it guesses correctly and hit ↩. This is called a Spotlight Search apparently and is the quickest way to find anything on a Mac but no-one tells you that!
Then create a new Application, and select PDFs on the left (highlighted in red), then Split PDF (also in red) and drag that into the "work-area" on the right.
I saved that then as splitter.
Then I started Terminal - same Spotlight Search method as starting Automator above, but start typing Terminal instead.
Now go to where you saved splitter and you'll see splitter.app:
ls -ld splitter*
drwxr-xr-x# 3 mark staff 96 27 Nov 12:09 splitter.app
Now I want to split a 10-page document called "a.pdf", so I ran:
echo "a.pdf" | automator -i - ./splitter.app
Sample Output
2018-11-27 12:15:21.200 automator[24004:3655998] Cache location entry for /Applications/Photos.app in cache file at /Users/mark/Library/Caches/com.apple.automator.actionCache-bundleLocations.plist is not valid: (null)
(
"/Users/mark/Desktop/a-page1.pdf",
"/Users/mark/Desktop/a-page2.pdf",
"/Users/mark/Desktop/a-page3.pdf",
"/Users/mark/Desktop/a-page4.pdf",
"/Users/mark/Desktop/a-page5.pdf",
"/Users/mark/Desktop/a-page6.pdf",
"/Users/mark/Desktop/a-page7.pdf",
"/Users/mark/Desktop/a-page8.pdf",
"/Users/mark/Desktop/a-page9.pdf",
"/Users/mark/Desktop/a-page10.pdf"
)
And it spits out 10 separate 1-page PDF documents on my desktop named per the output.
I have no idea what the warning about "Photos App" cache file means, so if anyone knows, maybe they would tell me what it means and how to get rid of it.
Also, I presume that Automator is somehow calling the action from /System/Library/Automator/Split PDF.action:
file "/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF"
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [i386:Mach-O bundle i386]
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF (for architecture x86_64): Mach-O 64-bit bundle x86_64
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF (for architecture i386): Mach-O bundle i386
But, I have no idea how I can execute/call that from Terminal, without needing to start/write any Automator stuff. So, if anyone, #vadian maybe, knows, I would love to know that too! It appears to be a bundle, but if I run mdls on it, there is no bundle identifier listed, so I cannot run it with:
open -b <BUNDLE-IDENTIFIER>
This will do it and let you set your resolution for the rasterization:
sips -s format png in.pdf -z 1024 1024 --out out.png
for all pdf files in directory and subdirectories:
find . -name "*.pdf" -exec sips -s format png {} -z 1024 1024 --out {}.png \;
the -exec part of this executes the rest as a command for each matching file until the \; terminator, while replacing {} with each file it finds. Super handy!

convert ~1000 swf to jpg / png / gif

I've got around 1000 swf (I even got the fla's) files I'd need to convert to any image (jpg, gif, png ...) with the only solution to save the fla as image at the moment. Not helpful with that amount.
Is there any command line tool I'd be able to use? I'm on Windows 7 or Ubuntu.
Already searched for a bunch of tools but they only convert one file at a time or have to be purchased.
Sidenote: the swf's aren't animated, just static pictures
Found a solution and want to share it:
I used sfwtools, which I installed with:
sudo add-apt-repository ppa:guilhem-fr/swftools
sudo apt-get update
sudo apt-get install swftools
Created a bash script using gedit (let's say it's called convertswf)
#!/bin/bash
for file in *.swf;
do
swfrender "$file" -o "$file.png"
done
or use this extended version if you have swf files in subfolders:
#!/bin/bash
for file in $(find "path/to/directory" -name '*.swf');
do
swfrender "$file" -o "$file.png"
done
finally did:
chmod +x convertswf
./convertswf
hope it helps!

Error creating disk image using hdutil

I'm trying to build dmg of .app file using following hdutil command:
hdiutil create -srcfolder /Users/me/My.app My.dmg
It works as expected as it creates My.dmg correctly. Problem started happening when I add two more files in to .app bundle before calling that hdutil command. The hdutil ends up with error:
diskimages-helper: resize request is above maximum size allowed.
hdiutil: create failed - Invalid argument
Thanks for any help you can provide.
I had the same problem. The solution I found at Apple Support Communities worked for me. I ended up adding an empty .Trash file into the folder before calling hdiutil:
touch root_folder/.Trash
or with Ant in my case:
<touch file="root_folder/.Trash"/>
You can optionally specify a '-size' parameter when you invoke hdiutil. If you specify a size large enough that the disk image doesn't need to be resized during .dmg creation, it seems you can avoid this error.
E.g.:
hdiutil create -size 240m -fs HFS+ -srcfolder test -volname Test test.dmg
I make images of folders like this:
hdiutil makehybrid -hfs -o output/path.dmg -hfs-openfolder input/path input/path

Creating DMG without extra space

I currently use hdiutil to create my DMGs.
The command I use is hdiutil create -size xxxg myImage.dmg -fs HFS+. I'm always left fidgeting around with the size until I get it close enough.
Is there a better method that either shrinks the DMG to size or creates it size?
Yes:
hdiutil create myImage.dmg -srcfolder SourceDir
This will automatically size the image to fit.
You can create a larger dmg, add the files, then resize it:
hdiutil resize -size xxxg myImage.dmg
or create a sparseimage, and then convert it
hdiutil convert -format UDZO Source.sparseimage -o myImage.dmg
I've never tried the latter, not sure if it'll pick the right size for the dmg.
Source: http://nickcharlton.net/post/converting-a-sparseimage-to-a-dmg
Note that sparseimages need to be compacted if files are deleted from them, as they don't release the space from deleted files automatically:
hdiutil compact Source.sparceimage

Resources