Bashing a broken feature of Apple Configurator 2

I have commented before on some of Apple Configurator 2's (AC2) broken features. There are even some new annoyances that have come to light that make me wonder if Apple hired some high school students for a weekend to program AC2.

One of the biggest things that Apple broke in AC2 that worked just fine in Configurator 1 (AC1) is related to the device names. If you manage a large set of shared iPads, you probably need to fully wipe the iPads from time-to-time to clear out personal user data. Wiping the iPads with a Prepare job is easy enough. Unfortunately, when you run the Prepare job, AC2 resets the names of the iPads and completely forgets the previously assigned names! This is a huge problem when you're trying to troubleshoot issues with a specific iPad. In AC1, the iPads would get renamed to the previously assigned name. I have no idea why Apple removed this functionality in AC2.

In my previous post, I described how to use AC2 in combination with AC1. The Prepare is done via AC2 (which has some iOS 9+ specific Prepare options not found in AC1), and then run AC1 to rename the iPads. Unfortunately, we just replaced the Macs used to manage our iPads and AC1 doesn't just want to rename the iPads, but now wipes them too (undoing the Prepare job). There may also be people out there who don't have AC1 (and don't feel comfortable retrieving it from some sketchy download site).

Bash to the rescue!

AC2 does include a very handy command-line utility that can be used in bash shell scripts to both capture the current device names, and apply those names back to the right iPads. To ensure the command-line utility is installed, click the Apple Configurator 2 menu, and choose "Install Automation Tools...". Now to create the files you will need.

First, let's create a mapping of device ID to current name. Make sure all of the iPads you want to manage are connected. Open a Terminal window and run the following commands.

mkdir ~/Desktop/Rename
/usr/local/bin/cfgutil list | sed -e 's/.*ECID: 0x/0x/' | sed -e 's/[ ]*UDID: .*Name: /,/' >> ~/Desktop/Rename/ipad_lookup.txt

Note that is a tab between the [ ]. You cannot just hit the tab key in Terminal for a tab. You must first press CTRL+V, then the tab key.

This will create a CSV (comma separated values) text file with the device ID to name mapping in a folder called "Rename" on your desktop. Save this file (make a backup somewhere). You don't want to lose it. Open the file with a text editor to make sure all of the iPads are listed. You should only need to run this command once unless you add more iPads or decide to rename them.

Once you have the above file, you can safely run a Prepare job. After the Prepare job is done, you will need a script to rename the iPads. Rather than give full details about how to create a script here, I will simply refer you to another site describing the process. It isn't hard, and you just need to do this once. Simply follow the steps there, copying in the following lines into the script.

#!/bin/bash
WORKDIR=~/Desktop/Rename
/usr/local/bin/cfgutil list | sed -e 's/.*ECID: 0x/0x/' | sed -e 's/.UDID:.*//' > $WORKDIR/connected_iPads
while read ECID; do
  IPADNAME=`grep $ECID $WORKDIR/ipad_lookup.txt | sed -e 's/.*,//'`
  /usr/local/bin/cfgutil -e $ECID rename "$IPADNAME"
done < "$WORKDIR/connected_iPads"
rm $WORKDIR/connected_iPads

Make sure to save the script in the Rename folder on your desktop. I named the script file "renameConnectediPads.sh".

That script first detects all connected devices. For each connected device, it looks up the unique device ID in the previously created ipad_lookup.txt file, and renames the iPad accordingly. You can run this script while AC2 is running, and watch the names change as the script runs.

There you have it. Bash scripting is extremely powerful, and in just a few lines it solves one of the most annoying problems with AC2.