Created
September 11, 2014 19:56
-
-
Save yanks/ebe582d5e26e3ba6f79f to your computer and use it in GitHub Desktop.
Find sim/app dir on disk, open in Finder.
This file contains 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 ruby | |
# This script will open the directory with the simulator/app that you specify. | |
# Usage: 'find_sim plus swa' results finding the iPhone 6 Plus applications directory | |
# and Swarm.app (for me!) | |
# If you want just the plus sim: 'find_sim plus' | |
# Why? Because the dir hierarchy is crazy. This is what it looks like: | |
# /Users/jeffforbes/Library/Developer/CoreSimulator/Devices/<device guid>/data/Containers/Bundle/Application/<app dir guid>/yourapp.app | |
def dir_matches(path, sim_name) | |
plist_file = "#{path}/device.plist" | |
plist = File.read(plist_file) | |
plist.match(/<string>.*[iPhone | iPad](#{sim_name})<\/string>/i) != nil | |
end | |
#searches simulator bundle for the app name | |
def app_matches(path, app_name) | |
@path = nil | |
Dir.entries(path).each() do |entry| | |
if entry.start_with?('.') then | |
next | |
end | |
full_entry_path = "#{path}/#{entry}" | |
if Dir.exist?(full_entry_path) then | |
Dir.entries(full_entry_path).each() do |app_bundle| | |
if app_bundle.match(/.*#{app_name}.*.app/i) then | |
@path = full_entry_path | |
break | |
end | |
end | |
end | |
end | |
@path | |
end | |
@ios_sim = nil | |
@app = nil | |
if (ARGV.length < 1) then | |
puts "usage: find_sim <device suffix e.g. '5' or '6'> <app name>" | |
exit 1 | |
end | |
@ios_sim = ARGV[0] | |
@app = ARGV[1] | |
@sim_dir = File.expand_path('~/Library/Developer/CoreSimulator/Devices') | |
@applications_path = 'data/Containers/Bundle/Application/' | |
if !Dir.exist?(@sim_dir) then | |
puts 'error: no developer dir found' | |
exit 1 | |
end | |
Dir.entries(@sim_dir).each() do |entry| | |
if (entry.start_with?('.')) then | |
next | |
end | |
full_dir = "#{@sim_dir}/#{entry}" | |
if Dir.exist?(full_dir) then | |
if dir_matches(full_dir, @ios_sim) | |
full_apps_path = "#{full_dir}/#{@applications_path}" | |
if [email protected]? then | |
app_path = app_matches(full_apps_path, @app) | |
if (app_path) then | |
system("open #{app_path}") | |
exit 0 | |
else | |
puts "error: couldn't find #{@app}, but could find sim" | |
exit 1 | |
end | |
else | |
system("open #{full_apps_path}") | |
exit 0 | |
end | |
end | |
end | |
end | |
puts "error: couldn't find sim. :(" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just realized I need to do a bit more here -- documents are hosted in a different place. Incoming!