Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Thursday, July 19, 2012

Command line script to batch convert images

Ever had a folder full of images that you needed to convert? Well, today I had a couple hundred 20Mb RAW images that I wanted to convert to JPG, and I really didn't want to open them on an image editor.

So I went hunting for a way to convert the images using the command line on the Mac. Here's what I found:

1. Converting an image via command line: There's a tool called "sips" that does this (and much more) on the mac! To convert a file from RAW to JPG, you just need to call something like:

sips -s format jpeg IMAGE.NEF --out IMAGE.jpg

2. Getting the right name: Iterating a list of files via command line is easy, getting just the filename in order to change the extension requires google! Here's how to do it:

for i in *.NEF; do echo "${i%.*}.jpg"; done

(curious on how it works? Check this doc)

3. All together now: To convert all the files in the current directory, do this:

for i in *.NEF; do sips -s format jpeg $i --out "${i%.*}.jpg"; done

Let me know how the script worked out for you!

Sunday, May 20, 2012

Moving from iPhoto to Lightroom

I've been using iPhoto since I bought my mac, but lately it seems to be getting slower and buggier... Takes ages to launch, search doesn't work properly, and my library of about 25,000 photos seems too much for it. So I decided to try Lightroom.

Unfortunately, there's no easy way to get out of iPhoto, be it for Lightroom, Picasa, or whatever... There's no simple way to export all of your events into nice subfolders! So I built my own way out!

I created a python script that reads the data from iPhoto, and uses it to create a tree structure with year/name_of_event and all the photos inside. Here's a screenshot of the script running:


To use the script, download it from here, and execute it via the terminal using:

python iphoto-to-folders.py [AlbumData.xml] [destinationDir]

[AlbumData.xml] is a file inside your iPhoto library, and can usually be located at ~/Pictures/iPhoto\ Library/AlbumData.xml

[destinationDir] is the folder where you want your photos to be copied to.

A couple of notes about the script:

  • It only copies the original versions of the photos. Changes you made in iPhoto are not copied.
  • It copies all the files from your iPhoto library, so it needs quite a bit of disk space.
  • It may take some time to run. To copy my 25.000 photos it took 1.5 hours
  • It's not supposed to mess with your iPhoto library, but do make backups!
  • It has no warranty whatsoever!
  • It's supposed to be tweaked! If you're comfortable with python, adapt the script to your needs.
If you have any questions or spot some problems, please submit them here. And be sure to leave a comment telling me how the script worked for you!

Saturday, September 13, 2008

Mighty Mouse design flaw

I bought a Mighty Mouse from Apple. I wanted a wireless mouse for my computer, and the Mighty Mouse seemed like the perfect choice for my Mac.

The mouse is beautiful, the buttons work pretty well and the scroll ball is great! But the mouse has a rather annoying design flaw:

You cannot lift the mouse while clicking!

Here's the problem: The mouse detects the button is pressed because you press the body of the mouse against the base of the mouse. When you lift the mouse, there's no longer pressure between the body and the base of the mouse. So our mighty mouse assumes you're no longer pressing the button.

There's somewhat of a work around for this... If you squeeze the mouse, the base does not drop and you can lift the mouse. But since squeezing the mouse brings up Exposé, things can get pretty weird...

This can be a real pain when you're trying to drag files from an end of the screen to another, or when you're trying to make a huge selection... it is one of those design vs. function options that I'm still not sure if Apple's done the right choice.

Tuesday, June 10, 2008

PHP on the Mac

If you have a Mac with Leopard and want to use PHP, most of what you need is already installed. It's just a matter of making it work.

First you need to turn on apache. Just go to your "System Preferences", "Sharing" and turn on "Web Sharing". That's it, apache is running. You can check if all is ok by going to http://localhost.

You'll probably want MySql too. Just go to their site, download and install. No big fuss, but make sure you install the StartupItem if you want MySql to start when the system boots.

Next you must enable PHP. Launch a terminal and use your favorite text editor to edit /etc/apache2/httpd.conf. Look for LoadModule php5_module and uncomment the line. Restart apache with sudo apachectl graceful.

Now let's say your username is john, and you have on your home folder a ~/dev/phpproj where your php code is. One way to make this available (and there's lots of others) is to edit /etc/apache2/users/john.conf and add the following to the bottom of the file (replace [ with "lesser than" and ] with "greater than". Blogger doesn't like those symbols):
Alias /phpproj/ "/Users/john/dev/phpproj/"
[Directory "/Users/john/dev/phpproj/"]
Options Indexes MultiViews
Order allow,deny
Allow from all
[/Directory]
Now you can access http://localhost/phpproj/ to view your app.

At this point you might get a MySql error stating that you /var/mysql/mysql.sock does not exist, just go back to your terminal window and type:

cd /var
sudo mkdir mysql
cd mysql
sudo ln -s /private/tmp/mysql.sock mysql.sock

That's it!

I bought a Mac!

About a year ago I wrote some reasons why I wasn't buying a Mac. Well, a year has come and gone an I bought a Mac! And so far, I'm very happy with it!

I could go on forever about what's so great about my Mac, how cool it is just to unpack it, how beautiful the hardware and software are, and all that. But you can read about a million posts on the web about that, so I won't bother.

Instead I'm going to focus on the parts that aren't so good. This way people switching from Ubuntu to Mac will know what to expect.
  1. You have to pay for the software: Oh yeah, most software is closed source and payed for. I really miss doing apt-get and it just works, no payment, no registration...
  2. The keyboard is... different: I have a portuguese keyboard. The Mac doesn't have a } anywhere visible on the keyboard! It took me a while to figure I had to type --9
  3. X11 compatible... kind of: You can run X apps on the Mac. I installed Gimp, and it works. But the UI is a bit clumsy... For starters, the keyboard shortcuts aren't the same for X and Mac (e.g. in Mac you copy with -c, in X with -c). Second, the windows interaction is awkward. In "X mode" you have to click the window to get the focus, then click the button on the window to make it work. Since the Gimp has multiple windows, this is very annoying.
  4. No out of the box NTFS write support: C'mon! I have an external 500Gb HD formatted in NTFS! I had to install MacFUSE from google to make it work!
  5. Only 2 USB ports: Good thing I have a hub!
  6. Strange video output: It has a mini-DVI. Never seen one before. Oh well, I don't have another monitor, so it's not a big problem.
And I can't remember anything else... but I only have the laptop for 4 days!

Don't get me wrong, I love my Mac! But, like all things, it has some downsides. And the biggest one AFAIK is the non-open nature of this platform. Still, if I was going shopping again today, I would still buy the Mac!