Using AppleScript and Automator to resize iOS & Android assets

When creating assets for mobile apps, it can be a pain – and a time drain – to manually resize multiple images to their relevant screen density. For example: 1x, 2x, 3x in iOS or MDPI, HDPI, XHDPI etc in Android.

There are several great plugins for Photoshop that automate this process; but little in the way of Mac-specific workflows: it’s time for AppleScript and Automator to come to the rescue!

With a little experimentation, I created an AppleScript that allows you to re-size and copy an image into various asset-specific subfolders. And with Automator magic, this can make your resizing process as simple as right-clicking on a file.

5 Steps to Heaven

  1. Copy the contents of this AppleScript file to the Clipboard.
  2. Open the Automator app in Mac OS, then create a new workflow of type ‘Service’.

  3. Set the input to your Service with ‘files or folders’ and ‘Finder’ in the dropdowns.

  4. Drag the ‘Run Applescript’ action into your workflow and then paste the contents of the AppleScript file into it.

  5. Save the Service using a descriptive name such as ‘Create Mobile Assets in Folders’.

Using the AppleScript file

  1. Save your image file somewhere at x4 of full size, i.e. XXXHDPI.
  2. Right click on theĀ image file in ‘Finder’ and choose the shiny new option that should now be in the drop-down menu.

  3. Subfolders will be created for each size ratio and the image will be copied into them.

As mentioned above, the script assumes that your image is already x4 of display size, i.e. XXXHDPI in Android terminology. If you need to change this, or customise the sizes and ratios, just edit the first two lines of the script accordingly.

I hope you find the workflow useful as it can save many hours of fiddling around!