Skip to content

Instantly share code, notes, and snippets.

@Ashung
Last active January 21, 2020 12:26
Show Gist options
  • Save Ashung/f35e0b7173cee653cef0c9443151363a to your computer and use it in GitHub Desktop.
Save Ashung/f35e0b7173cee653cef0c9443151363a to your computer and use it in GitHub Desktop.
Diff Sketch file with Kaleidoscope.
#!/usr/bin/env bash
sketchtool=/Applications/Sketch.app/Contents/Resources/sketchtool/bin/sketchtool
#echo $(python --version)
function extractSketchFile () {
sketchFile=$1
folder=${sketchFile%.sketch}
unzip -q -o "${sketchFile}" -d "${folder}"
jsons=$(find ${folder} -name *.json)
for json in ${jsons}; do
temp=${json%.json}.temp
python -m json.tool ${json} > ${temp}
mv ${temp} ${json}
done
}
extractSketchFile "/Users/ashung/Desktop/1.sketch"
extractSketchFile "/Users/ashung/Desktop/2.sketch"
ksdiff "/Users/ashung/Desktop/1" "/Users/ashung/Desktop/2"
#!/usr/bin/env bash
sketchtool=/Applications/Sketch.app/Contents/Resources/sketchtool/bin/sketchtool
function unzipSketchFile () {
file="$1"
folder="${file%.sketch}_diff"
# unzip
unzip -q -o "${file}" -d "${folder}"
# export artboard
${sketchtool} export artboards ${file} --use-id-for-name="YES" --overwriting="YES" --include-symbols="YES" --output="${folder}/artboards"
# format json
jsons=()
while IFS= read -r -d $'\0'; do
jsons+=("$REPLY")
done < <(find "${folder}" -name "*.json" -print0)
for json in "${jsons[@]}"; do
python -m json.tool "${json}" > "${json%.json}.temp"
mv "${json%.json}.temp" "${json}"
done
}
unzipSketchFile "/Users/ashung/Desktop/1.sketch"
unzipSketchFile "/Users/ashung/Desktop/2.sketch"
ksdiff "/Users/ashung/Desktop/1" "/Users/ashung/Desktop/2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment