Skip to content

Instantly share code, notes, and snippets.

@derencius
Created March 10, 2011 03:05
Show Gist options
  • Save derencius/863511 to your computer and use it in GitHub Desktop.
Save derencius/863511 to your computer and use it in GitHub Desktop.
Download Xcode using wget. Useful for slow or intermittent connections. it uses wget and mechanize.
require 'rubygems'
require 'mechanize'
if ARGV.size < 3
puts %q{Usage: ruby xcode.rb USERNAME PASSWORD "DOWNLOAD_URL" [WGET_PARAMS]}
puts %q{Example: ruby xcode.rb [email protected] 123456 "https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/xcode_4_and_ios_sdk_4.3__final/xcode_4_and_ios_sdk_4.3__final.dmg" }
exit
end
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get('https://developer.apple.com/') do |page|
member_page = a.click(page.link_with(:text => /Member Center/))
login = member_page.form_with(:name => 'appleConnectForm') do |form|
form.theAccountName = ARGV[0]
form.theAccountPW = ARGV[1]
end.submit
a.redirect_ok = false
download_page = a.get(ARGV[2])
system %Q{ wget #{download_page.response["location"]} --header="Cookie: #{download_page.response["set-cookie"]}" #{ARGV[3]}}
end
@lorenzo-stoakes
Copy link

This is extremely awesome. Cheers :)

@YuaShizuki
Copy link

I am getting this error while running this script

xcode.rb:17:in block (2 levels) in <main>': undefined methodtheAccountName=' for nil:NilClass (NoMethodError)
from (eval):23:in form_with' from xcode.rb:16:inblock in

'
from /var/lib/gems/2.1.0/gems/mechanize-2.7.3/lib/mechanize.rb:442:in get' from xcode.rb:14:in'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment