Skip to content

@dav /gist:3738695
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Script to copy photos/videos into iPhone Simulator
require 'etc'
require 'fileutils'
# Copies the most recent MAX_IMAGES photos/videos from the device image dir.
# I use Dropbox to sync my device images to my workstation disk
MAX_IMAGES=500
USER_HOME_DIR = Etc::getpwuid.dir
DEVICE_IMAGES_DIR="#{USER_HOME_DIR}/Dropbox/Camera Uploads"
SIMULATOR_IMAGES_DIR="#{USER_HOME_DIR}/Library/Application Support/iPhone Simulator/5.1/Media/DCIM/100APPLE"
unless Dir.exists? DEVICE_IMAGES_DIR
puts "No such images directory: #{DEVICE_IMAGES_DIR}"
exit
end
unless Dir.exists? SIMULATOR_IMAGES_DIR
puts "No such images directory: #{SIMULATOR_IMAGES_DIR}"
puts "Create it? [y/n]"
answer = STDIN.gets.chomp.downcase
unless answer == 'y' || answer == 'Y'
puts "Ok. Not creating."
exit
end
puts "Creating #{SIMULATOR_IMAGES_DIR}"
FileUtils.mkdir_p SIMULATOR_IMAGES_DIR
end
files_sorted_recent_first = Dir.entries(DEVICE_IMAGES_DIR).sort do |a,b|
File.mtime("#{DEVICE_IMAGES_DIR}/#{a}") <=> File.mtime("#{DEVICE_IMAGES_DIR}/#{b}")
end
filecount = 0
files_sorted_recent_first.each do |filename|
ext = File.extname(filename).downcase
if %w(.jpg .mov .png).include? ext
filecount += 1
puts "File #{filecount}: #{filename}"
device_path = "#{DEVICE_IMAGES_DIR}/#{filename}"
simulator_path = "#{SIMULATOR_IMAGES_DIR}/IMG_%04d#{ext}" % filecount
mtime = File.mtime(device_path)
system "cp \"#{device_path}\" \"#{simulator_path}\""
File.utime(mtime, mtime, simulator_path)
break if filecount >= MAX_IMAGES
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.