Jul 23, 2013

How to burn (write) an ISO image to USB drive in all new Mac OS X systems

There are many programs in the market that can handle it for you. But you can do it with default Mac OS X tools. Those steps must be made in terminal. You need to know what you are doing and have root password to your system.
Here is your step by step guide to do it:


1. Convert your image.

You need to change the image type from .iso to .img that dd util supports. To do this type a command like this:
hdiutil convert -format UDRW -o /path/to/destination/file.img /path/to/source/file.iso
You must see output similar to this:
Reading Image File Name Here  (Apple_UDF : 0)…... [ truncated ] .............................
Elapsed Time:  4m 57.725s
Speed: 20.9Mbytes/sec
Savings: 0.0%
created: /path/to/image/file.img.dmg

2. Remove the .dmg extension.

mv /path/to/image/file.img.dmg /path/to/image/file.img

3. Get your flash drive device name.

You can do it in various ways. one that is using standard utils here:
diskutil list
This will list all your disks mounted to your mac. Output should be similar to this:
$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *750.2 GB   disk0
   1:                  Apple_HFS Vault                   750.2 GB   disk0s1
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *128.0 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS Mac OS HD               127.2 GB   disk1s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk1s3
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *16.0 GB    disk3
   1:                 DOS_FAT_32 UNTITLED                16.0 GB    disk3s1
So in my case flash drive is named disk3. Note it is not disk3s1, that indicates a partition name not a drive name.

4. Unmount your flash drive.

Note you need to unmount, not eject this flash drive. Command may be like so:
diskutil unmountDisk /dev/disk3
Change that disk3 to your device id.

4. Write your image to flash drive.

To handle this you would use a dd utility. Note param bs=1m, indicating block size to write. Missing this parameter would force dd to run byte by byte copy, resulting run for ages with several gigs of data.
sudo dd if=/path/to/image/file.img of=/dev/rdisk3 bs=1m
Note to change that disk3 to your flash drive id.
You may use rdisk instead of dd to add some speed to this. But this particular run was ok for me.
You may see an output like this, resulting you may eject and use your flash drive farther.
$ sudo dd if=/path/to/image/file.img of=/dev/rdisk3 bs=1m
Password:
6207+1 records in
6207+1 records out
6509363200 bytes transferred in 1124.570118 secs (5788312 bytes/sec)

Hope this help somebody someday. Cheers.
Please comment and share!

Jul 13, 2013

Python converting PDF to Image

I have a task to generate thumbnails of uploaded PDF's. And seems like there no really solid decisions yet. Just garbage on the surface in google results. after googling for a while I found out about many ways to do so. E.g. use python stdin/out to run external command line tool. It might work for you to. But it seemed not so pythonic for me. So I have searched fo better decision. My current is for now to install ImageMagick and MagicWand binding.

Install ImageMagick.

I have used PIL a while ago to work with images. But it made me cry, before I have met sorl-thumbnails. It helped me a lot. But now I have to deal with PDF's. And ImageMagick seems like a complete decision to master it all.  It has to convert pdf to my direct desirables - jpeg. So to install ImageMagick I have used brew. Like this:
brew install imagemagick
However there are many other ways to do so, depending on a platform. But I strongly recommend to look at brew.

Anyway installing ImageMagick is tricky. And in order to have it installed to work with pdf's we need to have freetype and ghostscript packages. In case of absence of ghostscript you could have error like so:
wand.exceptions.DelegateError: Postscript delegate failed 'file.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/682
In case of freetype package absence you will have you PDF rendered without fonts. So be sure those 2 are certainly installed.

Installing Wand

There are several high level bindings for ImageMagick for python, But I have chosen wand as my favorable here.
This is strongly depends on a platform. But nowdays fortunately I can do:
pip install Wand
And I'm happy with it.
Wand is simple enough for my task so I can do convert PDF to image and do simple transformations of my choice with it.

Working with it

Now that we have those things installed we may convert a pdf into image and resize it afterwards.
from wand.image import Image
# Converting first page into JPG
with Image(filename="/thumbnail.pdf[0]") as img:
     img.save(filename="/temp.jpg")
# Resizing this image
with Image(filename="/temp.jpg") as img:
     img.resize(200, 150)
     img.save(filename="/thumbnail_resize.jpg")
I'm sure there are better solutions here.  Note this is a simplified example to show the whole point of this method.

Feel free to suggest better solution in comments.

Jul 11, 2013

Show system files in Finder

Default Mac OS X system behavior is to hide system and hidden unix files (usually starting with a . symbol, e.g.: .bash_history will be out of sight). This makes spotting/opening one of this files with Finder extremely difficult.

you may use your terminal, typing command like "ls -a" that will show all of the files in that particular directory, including hidden and system one's. But sometimes it may become annoying to use terminal while using the GUI.

So. To change this default behavior in finder you need to enter those commands in the terminal window:
defaults write com.apple.finder AppleShowAllFiles TRUE
And after this you need to restart all your Finder processes like so:
killall Finder

Comments?