March 13, 2006

DropScript

One of the grooviest things about running a Mac is getting to play with its Unixy core, because there are scads of free tools that do scads of cool and useful things. Strangely enough, Apple has never bothered to include one of the coolest tools available in their download list. It's called DropScript (follow the "DropScript" link for the disk image).

DropScript packages a shell script into a handy little droplet that lets you drop a file on it and then passes the filename and the script to the shell to let it work some magic. Or even magick.

The DropScript droplets I use the most are ones that convert the ginormous digital photos that I take into reasonable sized ones for emailing clients and friends.

The first one below is a favorite of mine. It resizes any image (or any bunch of images, but not a folder) you drop on it to an 800 pixel maximum width or height, and also swaps any spaces in the filename to underscores and makes it lower case. The image you drop will be replaced, so use this on a copy of your image, not the original, or you'll be sorry. The second version does the same thing, but also creates a separate thumbnail.

There are plenty of variations possible just by tweaking these scripts. Just read the linked man pages for the commands in the scripts. There is likely some clumsiness in my use (or misuse) of the commands in the scripts. I'm not a shell script expert by any stretch of the imagination.

For the following shell script to work, you'll need to have ImageMagick properly installed. The easiest way to do this is to use Marc Liyanage's ImageMagick package. Trust me, it's a heck of a lot easier than trying to do it yourself.

Caveats:
This works well if your droplet and the images are in the same place. It can also work between any two folders on your hard drive, but if there are spaces in any of the folder names in the path between the droplet and the images, the renaming won't work. I'm not sure what the mechanics of this are. And if I was smarter, I might be able to figure out how to pass folders of images as well. Perhaps someone could enlighten me.

Dropscript itself works as a droplet. Save either of the following two sections (starting with #!/bin/sh and ending with "done") as a plain text file (typically filename.sh), and then just drop it on the DropScript app.

----------------------------------------------------

#!/bin/sh

##
# Converts an image to 800 pixel max size.
# Destroys the original image.
# Changes filenames to lowercase and replaces spaces with "_".
##

for file; do
/usr/local/bin/convert -scale 800x800 -quality 50  "$file" "$file";
mv "$file" `echo "$file" | sed "s/\ /_/g" | tr [:upper:] [:lower:]` ;
done

----------------------------------------------------

#!/bin/sh

##
# Converts an image to 800 pixel max size.
# Destroys the original image.
# Creates a 150 pixel thumbnail with "_tn" appended to its filename.
# Changes filenames to lowercase and replaces spaces with "_".
##

for file; do
/usr/local/bin/convert -scale 800x800 -quality 50  "$file" "$file" ;
/usr/local/bin/convert -scale 150x150 -quality 50  "$file" `echo "$file" | sed "s/\ /_/g" | sed "s/\./_tn./g" | tr [:upper:] [:lower:]` ;
mv "$file" `echo "$file" | sed "s/\ /_/g" | tr [:upper:] [:lower:]` ;
done

----------------------------------------------------

* A droplet is an old Mac concept that usually refers to an AppleScript droplet. DropScript isn't Applescript, but it uses the same basic idea.

Posted by Hal Eckhart at March 13, 2006 08:12 AM | TrackBack
Comments
Post a comment
spam and annoying comments will be deleted







Remember personal info?




enter this number security code in the box below (prevents comment spam)