XCode - how to automate the "install additional component" at first start

Bernard_Huang
Contributor III

Hi all,

I've search for this topic a bit, but can't find an answer. So I'm typing up a new question.

I install the latest XCode onto the Mac. During first start up, it will have this screen
1ca552c25db049bc850a4cc3db084a08 I would then click on install, and type in my admin password to perform the installation.

Now I want to automate this step, as I want to do this on multiple build agents that will regularly get the latest XCode available. Is there any command or script that will trigger this off?

11 REPLIES 11

hkabik
Valued Contributor

It used to be that you could script the contents of /Applications/Xcode.app/Contents/Resources/Packages to install as part of the initial install, but that doesn't seem to do it any longer. I haven't found a solve for this yet.

ICTMuttenz
Contributor

https://www.jamf.com/jamf-nation/discussions/21248/deploying-xcode-8-via-self-service-a-how-to

rickgmac
Contributor
Contributor

Try this

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/xcode_post_install_actions

AVmcclint
Honored Contributor

I can confirm that the script on rtouton's github page does work with xcode 9.4.1.

alexmcclements
Contributor

I'm getting that as well, I've tried Rich's script and a number of others without success.

alexmcclements
Contributor

I added this line to Rich's code and it now works, there is an additional package which now needs installed which isn't in the original script.

Install XcodeExtensionSupport.pkg so there is no prompt

if [[ -e "/Applications/Xcode.app/Contents/Resources/Packages/XcodeExtensionSupport.pkg" ]]; then
/usr/sbin/installer -dumplog -verbose -pkg "/Applications/Xcode.app/Contents/Resources/Packages/XcodeExtensionSupport.pkg" -target /
fi

Stevie
Contributor

We deploy our Xcode with the version number appended to the filename so that our developers can pick which version they want to used. We deploy the application then run the following three lines which work well.

sudo xcode-select -s /Applications/Xcode 10.0.app/Contents/Developer
sudo /usr/bin/xcodebuild -runFirstLaunch'
sudo /usr/bin/xcodebuild -license accept

BOBW
Contributor II

try this:
(based on @rtrouton work)

#!/bin/sh 

if [ -e /Applications/Xcode.app ]
then

sudo xcodebuild -license accept
# make sure all users on this machine are members of the _developer group 
/usr/sbin/dseditgroup -o edit -a everyone -t group _developer 
# enable developer mode 
/usr/sbin/DevToolsSecurity -enable 
# accept Xcode license 
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -license accept 
# install embedded packages 
# 
cd /Applications/Xcode.app/Contents/Resources/Packages/
sudo installer -pkg MobileDevice.pkg -target /
sudo installer -pkg MobileDeviceDevelopment.pkg -target /
# sudo installer -pkg XcodeExtensionSupport.pkg -target / ## no longer required
sudo installer -pkg XcodeSystemResources.pkg -target /

exit 0
else
echo "waiting for app trying again at next checkin"
exit 0
fi

BOBW
Contributor II

and yes you don't need the sudo.....

davidhiggs
Contributor III

this is worth looking at, very recent and carl's work is solid: https://github.com/carlashley/xcode_tools

jason_bracy
Contributor III

So, it looks like Apple has made this much easier now - don't know when they did it, but running the command:

sudo /usr/bin/xcodebuild -runFirstLaunch

Will accept the license and install all additional components.