Skip to content

Instantly share code, notes, and snippets.

@Ashung
Last active April 2, 2019 04:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashung/ef430b59a3797dd212070b7e4cc0549c to your computer and use it in GitHub Desktop.
Save Ashung/ef430b59a3797dd212070b7e4cc0549c to your computer and use it in GitHub Desktop.
Sketch file for Git, use as CLI, macOS Finder services, Automator App.
#!/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