Issue
I was trying to search for a quick command to extract the bundle identifier from a provisioning profile. I think I've seen something like that in the past, but I can't find it now.
Inspecting the .mobileprovision
file shows that it's a .plist
file, but not quite as it is surrounded by some binary data. I tried PlistBuddy
, but the binary data causes it to fail with the following error:
Unexpected character 0 at line 1
I think the command I saw in the past was just some regex to extract the wanted value. I know, don't parse XML with regex, but I think this is one of those times when it is acceptable. In fact, I would prefer a regex solution if it means that I do not have to install any dependencies.
Solution
TL;DR
security cms -D -i your.mobileprovision | plutil -extract Entitlements.application-identifier xml1 -o - - | grep string | sed 's/^<string>[^\.]*\.\(.*\)<\/string>$/\1/g'
The Details
The key here is that you can extract the plist from the provisioning profile using:
security cms -D -i your.mobileprovision > tmp.plist
Now that you have a proper plist, you can use PlistBuddy
as normal. I ended up using plutil
instead, because PlistBuddy
doesn't support reading from stdin and I didn't want to create a temporary file. Unfortunately plutil
outputs XML and not just the value of the property, but the Entitlements.application-identifier
property has the Team ID prepended, so I would have anyway needed regex to extract the bundle identifier.
If you have any suggestions on how to improve this command, I'm happy to hear them, but the command is working as expected and has solved my problem. Hopefully, someone else will find it useful as well.
Answered By - Erik B Answer Checked By - Mildred Charles (WPSolving Admin)