How to synchronize your iPhone or iPad in more than one computer

For a long time I struggled around the possibility of synchronizing any given iDevice, be it an iPhone, iPad or iPod Touch, in more than one computer. There were uncountable times that I received a client’s device to troubleshoot (for example, to see why he wasn’t being able to successfully install an AdHoc build), and  when I tried to synchronize it with my iTunes, there would be a message saying that all applications would be deleted. Heck, that’s not why I wanted to do.

Maybe I was looking at the wrong place or doing the wrong searches on Google, but it took me some time to figure out the correct approach to handle this problem. There are two possible situations you may face, which are:

1) Synchronize your own device in more than one computer

This is the simplest of the cases: you have an iPhone, iPad or iPod Touch, and want to sync it at your home’s computer and at your company’s computer. Please bear in mind that you are allowed to do such thing up to 5 computers. Connect your device via an usb cable and fire up iTunes, then go to the Store menu and choose Authorize This Computer. Enter your credentials, and after that go to the File menu and choose Transfer purchases from ….. Wait until it finishes, and you are good to go.

2) Synchronize more than one device in the same computer

This is a bit more elaborated, and handles the situation where you have multiple devices that you need to sync in the same computer – note that it’s a different need than the previous, where it states out to sync the device in different computers. The question here is how not to mess with your own library when someone else’s device is sync’d at your iTunes.

To correctly perform this task, you will need to think about multiple iTunes libraries (or multiple accounts), and then perform the steps previously described at (1). Do the following:

Quit iTunes, and before opening it again, hold down the Option key (Mac) or Shit key (Windows), and without releasing it, fire up iTunes. A dialog window saying that you should “Choose iTunes Library” will open, as shown in the image below:

Select “Create Library” and place it wherever you want. That would be the location where the files will be stored, so if you want to use it other than for temporary purposes, please make sure you choose a good directory.

One you do that, do the steps at (1). To switch between libraries, to the same Option or Shift trick again, but then select “Choose Library” instead.

Converting multiple PDF files into JPG using ImageMagick

ImageMagick is an extremely powerful program, which can do amazing things even with very simple arguments. One of the things I have been using ImageMagick recently was to convert PDF files into image files (JPG, PNG, GIF, you name it), that is a task that many think that only can be achieved using some comercial (and expensive) tool. The basic usage is effortless:

convert input.pdf output.jpg

ImageMagick’s convert command will take the PDF as input and create a JPG file as output. Note that the type of the output file is determined by its extension, so if you wanted to create a PNG file, just use output.png. More advanced results include specifying the pixel density, quality, resize, scale, colorspace, alpha channel etc.. the list goes on beyond you could imagine. For a complete and detailed set of commands, check http://www.imagemagick.org/script/command-line-options.php.

A more detailed example:

convert -alpha off -density 150 -quality 80 -resize 768 -unsharp 1.5 input.pdf output.jpg

The previous command will convert a PDF to JPG of quality 80, with 150 DPI and as last step, apply a 1.5 radius unsharp filter. Doing that with any programming language would require literally dozens of line of code.

One interesting option to note about is -alpha off, which prevents the JPG to be created with a black background. However, please note that may not be the case all the times, and you probably will have to adjust the arguments to fit your needs.

Batch processing

As a final example, the convert command requires either an input and an output names, but sometimes you want to the filename to be the same, just with a different extension (like Presentation_123.pdf => Presentation_123.jpg). This is very common when we have a set of pages in a given directory and want to convert them all. One easy way to accomplish that is by using the command mogrify instead of convert. mogrify works much like convert, but allows us to do some batch processing. For example:

mogrify -format jpg -alpha off -density 150 -quality 80 -resize 768 -unsharp 1.5 *.pdf

There are two different arguments: the first is the format we want to convert to, and the other is the format we are converting from. The form is mogrify -format <output type desired> [other arguments] *.<input type>, so if you want to convert all JPG files to PNG without changing the filename (only the extension), you’d execute

mogrify -format png *.jpg

Easy as eating chocolate.

Handling the “open() 11 resource temporarily unavailable” error with Nginx

While developing a website, I started receiving the error “open() 11 resource temporarily unavailable” after we migrated from Apache to Nginx. The symptom was that, after any change to a CSS or JS file (in fact, to any file directly served by Nginx) the first request would crash, but any subsequent request did work. However, after performing any kind of change in one of those files, the problem happened again.

One important thing to notice is that I was developing through Samba – more specifically, I had the Nginx server running on a local Linux box, and the files were being manipulated in a text editor in Windows.

What I found out is that, if I edited the files directly in the Linux box, the problem didn’t happen. Going a little bit further, it was clear that changing to another text editor in Windows would not trigger the problem. After some Googleing, a post in the Nginx users list mentioned that this issue may arrive due to the fact that some text editors perform some kind of temporary lock at Samba in the files being edited (although I couldn’t find anything visually, at least), which caused Nginx to not being able to open the file even for reading.

So, if you have an environment like mine and are running into this issue, try swapping to another editor. You may have luck.