Using the Unix command line in Mac OS X to manipulate images

Dec 1, 2006 - 4 Comments

Anytime I find myself doing a repetitive task, it is crucial that I discover small tricks and workarounds to make my daily routine as efficient as possible. I have long been a Linux user, so naturally I lean towards opening up the Terminal and using the familiar bash shell environment that I have mastered on many different operating systems. I’m really happy that Apple decided to build Mac OS X on top of a Unix, as it immediately opened the door for any Unix user to jump right in and feel at home within the Macintosh community. Ok – well, maybe not feel “at home”, but it is quite comforting to be navigating my MacBook Pro’s filesystem with my keyboard. Enough of that, lets get into my latest use of the command line in Mac OS X.

So first, I present to you our dilemma:

When writing a review on a Mac OS X Application, we must manually extract an icon from the .app and then convert it to the jpeg format. Oh, and by the way, we only post images on the front page that have dimensions of 112×112.

And now the solution:

How to Manipulate Images via Command Line in Mac OS

Open Terminal.app, which is found in /Applications/Utilities/

Type the following (if your Stickies.app is not in the Applications folder you’ll need to change the first command accordingly):

cd /Applications/Stickies.app/

cd Contents/Resources/

ls

cp Stickies.icns ~/Desktop

cd ~/Desktop

sips -Z 112x112 -s format jpeg ./Stickies.icns --out ./Stickies.jpg

If everything went according to plan you should have a lovely, well-scaled jpeg version of the Stickies icon on your desktop.

Now, because sips is affectionately called the scriptable image processing system, lets make a script to do this for us. Keep in mind, this script could be considered overkill, but its a good exercise in harnessing some of the stuff I’ve learned in the Linux/Unix world in Mac OS X.

Download this file (yankicn.sh.txt).

Rename it to yankicn.sh, and move it into your “Home” folder (accessible by hitting Apple-Shift-H).

Open the terminal and type:

chmod +x yankicn.sh

Now use it by typing:

./yankicn.sh -a /Applications/Stickies.app/

And get even more clever, and change the size and format.

./yankicn.sh -a /Applications/Stickies.app -s 128x128 -f png

In both scenarios you will have a converted image on your desktop.

For an applescript-ish way of manipulating images, out this page: Mac OS X Hints. Note that this applescript is not doing the same thing my shell script does. But it is certainly a starting point.

.

Related articles:

Posted by: Bill Ellis in Command Line, How to, Mac OS, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. geosocial says:

    Your absoloutley right. people these days are worrying too much about the equipment other than there swings. well said mark. 

  2. soho says:

    ^lol, same ending as previous poster :D

  3. soho says:

    I’m also using the CLI pretty regularly, but for this kind of image manipulation, there’s another elegant way: ImageWell. The workflow isn’t quite that sophisticated compared to an automated version:

    go to Applications folder > browse app pack > find icon file of app > drag&drop to ImageWell etc. – you get the idea.
    On the other hand: you can easily configure this tool to upload to a (s)ftp, idisk or webdav folder, resize, and other stuff.

    Anyway, keep those tips coming!

  4. Chris says:

    Yes! I have previously installed the ImageMagick package for OS X from http://www.entropy.ch/software/macosx/ in order to do command line image manipulation, but I always love to find out that things like this come installed in OS X.

    Thanks, keep these tips coming!

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site