Skip to content

Instantly share code, notes, and snippets.

@martinklepsch
Created March 7, 2012 14:13
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 martinklepsch/1993352 to your computer and use it in GitHub Desktop.
Save martinklepsch/1993352 to your computer and use it in GitHub Desktop.
Script to download Command Line Tools for XCode

Script to Download Apple's Command Line Tools For Xcode

This is a script which will download and install Apple's Command Line Tools for Xcode by using Applescript.

It requires credentials of an Apple developer account.

NOTE: This is not working yet. If you feel a use for it, test it and fix what you can.

tell application "Safari"
make new document at end of every document
--> document "Ohne Titel"
set URL of document 1 to "https://developer.apple.com/downloads/index.action"
get name of document 1
--> "Ohne Titel"
do JavaScript "var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
head.appendChild(script);" in document 1
--> missing value
do JavaScript "alert('test')" in document 1
--> missing value
do JavaScript "document.forms['appleConnectForm']['accountname'].value = 'somename'" in document 1
--> missing value
do JavaScript "document.forms['appleConnectForm']['accountpassword'].value = 'somepassword'" in document 1
--> missing value
do JavaScript "document.appleConnectForm.submit();" in document 1
--> missing value
do JavaScript "var atags = document.getElementsByTagName('a')" in document 1
--> missing value
do JavaScript "for (var i=0; i<atags.length; i++){ if (atags.textContent=='Command Line Tools for Xcode'){ atags[i].click(); } }" in document 1
--> missing value
set name of window 1 to "Ohne Titel"
end tell
set loginurl to "https://developer.apple.com/downloads/index.action"
set mylogin to "somename"
set mypassword to "somepassword"
tell application "Safari"
make new document at end of documents
set URL of document 1 to loginurl
set oldName to (name of document 1) as string
--This subroutine makes sure the page has finished loading -- it expects the page to finish with the "</html"> tag
--my waitforload()
--now that the page has loaded, we use Javascript inside Safari to fill in the form and click the submit button!
do JavaScript "var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
head.appendChild(script);" in document 1
do JavaScript "alert('test')" in document 1
do JavaScript "document.forms['appleConnectForm']['accountname'].value = '" & mylogin & "'" in document 1
do JavaScript "document.forms['appleConnectForm']['accountpassword'].value = '" & mypassword & "'" in document 1
-- do JavaScript "debugger;" in document 1
do JavaScript "document.appleConnectForm.submit();" in document 1
do JavaScript "var atags = document.getElementsByTagName('a')" in document 1
do JavaScript "for (var i=0; i<atags.length; i++){ if (atags.textContent=='Command Line Tools for Xcode'){ atags[i].click(); } }" in document 1
set name of window 1 to oldName
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment