Making a JPG Optimizer Application

Purpose

Drag & Drop an image file into the Dock.

The image gets automatically optimized for the web:

1. Create a terminal application that can handle drag and drop files

To make it simple, let's create an app that just display the filename we pass through drag & drop.

  1. Open Automator
  2. Choose Application
  3. Filter with shell
  4. Choose Run shell script
  5. Shell /bin/bash
  6. Pass input as arguments

Script content:

#!/bin/bash
for f in "$@"
do
  osascript -e "display notification \"$f\""
done

Go to menu File --> Export

2. Create the converter application

We keep the same process, and change the script with the following:

#!/usr/local/bin/bash
for f in "$@"
do
  ext="${f##*.}"
  newf="${f/%.$ext/.jpg}"
  /usr/local/bin/convert -resize 980x980 -quality 60 "$f" "${newf}"
done