Skip to content

Instantly share code, notes, and snippets.

@blakejakopovic
Forked from gertig/appcrush.rb
Created July 3, 2013 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blakejakopovic/5919365 to your computer and use it in GitHub Desktop.
Save blakejakopovic/5919365 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -rubygems
#
# Point appcrush at an .ipa file from the iTunes AppStore and it
# - expands the zip file
# - finds all the images
# - runs pngcrush with the revert-iphone-optimizations option on each image
#
# Requirements Xcode with iOS SDK 3.2 or higher
#
# Usage: appcrush '/Users/boctor/Music/iTunes/Mobile Applications/iBooks.ipa'
#
# Author: Peter Boctor
# http://idevrecipes.com
# https://github.com/boctor/idev-recipes/Utilities/appcrush
# Version 1.0
#
# Copyright (c) 2011 Peter Boctor
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE
#
# Only pngcrush in 3.2 and above supports revert-iphone-optimizations
# See http://developer.apple.com/library/ios/#qa/qa2010/qa1681.html
# Run
# $ xcrun -sdk iphoneos5.1 -find pngcrush
# To find the path for your pngcrush, add that as the string below
# Then
# $ appcrush.rb '/Users/andrewgertig/Music/iTunes/iTunes Media/Mobile Applications/GroupMe 3.3.4.ipa'
# Will create a folder on your desktop with the images in it from that app
# developer_root = "`xcode-select -print-path`".chop
# developer_root = "'xcode-select --print-path'".chop
# pngcrush = "#{developer_root}/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush"
pngcrush = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush"
# pngcrush = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush'
destination = File.join(ENV['HOME'], 'Desktop')
ARGV.each do |ipa|
if File.extname(ipa) == '.ipa'
# Get the app name by stripping out the extension from the file name
app_name = File.basename(ipa, ".*")
# Get the expanded dir by stripping out the extension from the file path
expanded_dir = ipa.sub(File.extname(ipa), '')
# In case the dir is already there, try and remove it
system "rm -drf '#{expanded_dir}'"
# Extract .ipa zip file
system "unzip -q '#{ipa}' -d '#{expanded_dir}'"
images_dir_path = File.join(destination, "#{app_name} Images")
# In case the destination directory is already there, try and remove it
system "rm -drf '#{images_dir_path}'"
# Create the destination directory
Dir.mkdir(images_dir_path)
# Iterate through all png images
Dir.glob(File.join(expanded_dir, 'Payload', "*.app", '*.png')).each do |png_file|
# and revert the iphone optimizations
png_crush_command = "#{pngcrush} -q -revert-iphone-optimizations -d '#{images_dir_path}' '#{png_file}'"
# puts "#{png_crush_command}"
system png_crush_command
# system "#{pngcrush} -revert-iphone-optimizations -q '#{png_file}' '#{images_dir_path}/#{png_file}'"
# system "#{pngcrush} -revert-iphone-optimizations -q '#{images_dir_path}' '#{png_file}'"
# system "#{pngcrush} -q -revert-iphone-optimizations -d '#{images_dir_path}' '#{png_file}'"
end
# Iterate through all jpg images
Dir.glob(File.join(expanded_dir, 'Payload', "*.app", '*.jpg')).each do |jpg_file|
# and move each to the destination directory
system "mv '#{jpg_file}' '#{images_dir_path}'"
end
# Iterate through all pdf images
Dir.glob(File.join(expanded_dir, 'Payload', "*.app", '*.pdf')).each do |pdf_file|
# and move each to the destination directory
system "mv '#{pdf_file}' '#{images_dir_path}'"
end
# Cleanup. Delete the expanded dir
system "rm -drf '#{expanded_dir}'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment