Skip to content

Instantly share code, notes, and snippets.

@brysgo
Created February 14, 2014 19:43
Show Gist options
  • Select an option

  • Save brysgo/9007731 to your computer and use it in GitHub Desktop.

Select an option

Save brysgo/9007731 to your computer and use it in GitHub Desktop.
Install xcode command line tools without prompt
do shell script "xcode-select --install"
do shell script "sleep 1"
tell application "System Events"
tell process "Install Command Line Developer Tools"
keystroke return
click button "Agree" of window "License Agreement"
end tell
end tell
@pearofducks

Copy link
Copy Markdown

If this is saved as an app named CLT.app, this command will enable the applescript to run without needing to specifically enable it as an Assistive Device in Mavericks.

sudo sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db "INSERT INTO access VALUES('kTCCServiceAccessibility','com.apple.ScriptEditor.id.CLT',0,1,1,NULL);"

@brysgo

brysgo commented Apr 8, 2014

Copy link
Copy Markdown
Author

Thanks @pearofducks ! I was wondering why it worked from the AppleScript editor but not from the terminal.

@zlx

zlx commented Apr 28, 2015

Copy link
Copy Markdown

Great script. But now I face a problem: the script exit and raise "The command exited with a non-zero status." when the xcode command line tools is installing

@dcondrey

dcondrey commented Jun 8, 2015

Copy link
Copy Markdown
xcode-select --install
sleep 1
osascript <<EOD
  tell application "System Events"
    tell process "Install Command Line Developer Tools"
      keystroke return
      click button "Agree" of window "License Agreement"
    end tell
  end tell
EOD

@furiml

furiml commented Aug 19, 2016

Copy link
Copy Markdown

Very useful. Thanks !
I'm trying to add something to close the last window, when everything is installed... I'm totally new to applescript, but here's what I wrote :

tell application "System Events"
  tell process "Install Command Line Developer Tools"
    keystroke return
    click button "Agree" of window "License Agreement"
    repeat
      if (get properties of button 1 of window 1) contain "Done" then exit repeat
    end repeat
    close every window
  end tell
end tell

Can you tell me where I'm wrong ?

@blackthroat

Copy link
Copy Markdown

@furiml Did you ever figure out your addition of closing the last window?

@borisceranic

borisceranic commented Oct 17, 2018

Copy link
Copy Markdown

@furiml Did you ever figure out your addition of closing the last window?

You can side step the problem by testing the exit code of xcode-select --install before even launching AppleScript.

Maybe something along the lines of:

xcode-select --install > /dev/null 2>&1
if [ 0 == $? ]; do
    sleep 1
    osascript <<EOD
tell application "System Events"
    tell process "Install Command Line Developer Tools"
        keystroke return
        click button "Agree" of window "License Agreement"
    end tell
end tell
EOD
else
    echo "Command Line Developer Tools are already installed!"
fi

@senguttuvang

Copy link
Copy Markdown

Encountered exception when attempting to run it from Terminal

zsh: parse error near `do'

@brysgo

brysgo commented Aug 24, 2020

Copy link
Copy Markdown
Author

I don't know what this does anymore as it is from seven years ago, but it is an apple script so you will need to run it with applescript and not zsh

@dspolleke

dspolleke commented Apr 7, 2021

Copy link
Copy Markdown
xcode-select --install > /dev/null 2>&1
if [ 0 == $? ]; then
    sleep 1
    osascript <<EOD
tell application "System Events"
    tell process "Install Command Line Developer Tools"
        keystroke return
        click button "Agree" of window "License Agreement"
    end tell
end tell
EOD
else
    echo "Command Line Developer Tools are already installed!"
fi

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