Last active
April 2, 2019 04:57
-
-
Save Ashung/ef430b59a3797dd212070b7e4cc0549c to your computer and use it in GitHub Desktop.
Sketch file for Git, use as CLI, macOS Finder services, Automator App.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
sketchtool=/Applications/Sketch.app/Contents/Resources/sketchtool/bin/sketchtool | |
for f in "$@" | |
do | |
# Sketch file | |
if [ -f "${f}" -a ${f##*.} = "sketch" ] | |
then | |
folder="${f%.sketch}" | |
# unzip Sketch files | |
unzip -q -o "${f}" -d "${folder}" | |
# export artboards | |
${sketchtool} export artboards "${f}" --use-id-for-name="YES" --overwriting="YES" --include-symbols="YES" --output="${folder}/artboards" | |
# formate JSON files | |
cd "${folder}" | |
jsons=$(find . -name "*.json") | |
for json in ${jsons} | |
do | |
python -m json.tool ${json} > temp && mv temp ${json} | |
done | |
fi | |
# Sketch folder | |
if [ -d "${f}" -a -d "${f}/pages" -a -f "${f}/user.json" -a -f "${f}/meta.json" -a -f "${f}/document.json" ] | |
then | |
# remove artborads folder | |
if [ -d "${f}/artboards" ] | |
then | |
rm -rf "${f}/artboards" | |
fi | |
# zip | |
cd "${f}" | |
zip -q -r "../${f##*/}.sketch" * -x .DS_Store | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment