Skip to content

Instantly share code, notes, and snippets.

@rasagy
Last active May 19, 2016 11:20
Show Gist options
  • Save rasagy/6d30a165b6bb6336259c to your computer and use it in GitHub Desktop.
Save rasagy/6d30a165b6bb6336259c to your computer and use it in GitHub Desktop.
Rearrange Android Assets exported from Sketch
# Quick hack for exporting assets for android, expanded on the tip in this article: https://medium.com/@lmindler/using-sketch-3-and-a-bit-of-fairy-dust-for-a-better-android-workflow-f667d0048855#.ssmzsmkko and the script here: http://f.cl.ly/items/3E3Q0N2M3m2Q1q322L0j/android_asset_organizer.txt
# Use Sketch Export to export each asset in one folder with suffix as: -mdpi (1x), -hdpi (1.5x), -xhdpi (2x), -xxhdpi (3x), -xxxhdpi (4x)
# Then, open terminal in that folder and run this command.
# Find all exported assets in a separate ../res/ folder.
# My directory structure is as follows:
# /Assets/
# /Exported from Slack/
# /res/
# /iOS/
# Terminal command should be run in /Exported from Slack/ so it moves the assets to ../res/ folder. I tend to move the rest to iOS (not automated in this script).
# Feel free to remove ../ in case you want the res folder _inside_ your assets folder.
mkdir ../res; mkdir ../res/drawable-xxxhdpi; mkdir ../res/drawable-xxhdpi; mkdir ../res/drawable-xhdpi; mkdir ../res/drawable-hdpi; mkdir ../res/drawable-mdpi
for file in $(find . -type f -iname '*-xxxhdpi*'); do
mv "$file" "../res/drawable-xxxhdpi/${file/-xxxhdpi/}"
done
for file in $(find . -type f -iname '*-xxhdpi*'); do
mv "$file" "../res/drawable-xxhdpi/${file/-xxhdpi/}"
done
for file in $(find . -type f -iname '*-xhdpi*'); do
mv "$file" "../res/drawable-xhdpi/${file/-xhdpi/}"
done
for file in $(find . -type f -iname '*-hdpi*'); do
mv "$file" "../res/drawable-hdpi/${file/-hdpi/}"
done
for file in $(find . -type f -iname '*-mdpi*'); do
mv "$file" "../res/drawable-mdpi/${file/-mdpi/}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment