Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8/xcodebuild: how to trigger 'Update Signing' from command line?

Background: Xcode 8 has new facilities to 'Automatically Update Signing'. With no provisioning profiles on the building mac, Xcode will automatically pull the required profiles from the Apple dev portal. One can rm -rf ~/Library/MobileDevice/Provisioning\ Profiles then open Xcode project, and Xcode will pull the profiles automatically, one will see 'Update Signing' in Xcode:

xcode update signing message

How does one trigger this 'Update Signing' from the command-line? The man page for xcodebuild has no mention of this. Simply running an 'xcodebuild' does not run this step.

like image 855
Garvan Keeley Avatar asked Sep 04 '25 16:09

Garvan Keeley


1 Answers

There is no way to do this using xcodebuild.

However, I've got a work-around that seem to be getting the task done for me. I use AppleScript to open the workspace in Xcode, wait an appropriate amount of time (say 10 seconds) and then quit Xcode. The signing update is done when the workspace is opened, not when you try to build, so this is sufficient to get any signing problems fixed.

The AppleScript I use is this (based on some code I found lying around the internet):

tell application "/Applications/Xcode.app"

    open "/Users/gary/MyWorkspace.xcworkspace"
    set workspaceDocument to workspace document "MyWorkspace.xcworkspace"
    -- Wait for the workspace document to load with a 60 second timeout
    repeat 120 times
        if loaded of workspaceDocument is true then
            exit repeat
        end if
        delay 0.5
    end repeat
    if loaded of workspaceDocument is false then
        error "Xcode workspace did not finish loading within timeout."
    end if

    -- Xcode will only update the signing for targets in the active scheme,
    -- so make sure the required scheme is the active one
    set schemeToUse to scheme "SchemeToUse" of workspaceDocument
    set active scheme of workspaceDocument to schemeToUse

    -- The time taken to update signing issues is related to the number of targets.
    -- The number of targets built by a scheme is not exposed through AppleScript,
    -- so count the total number of targets in the workspace 
    set totalTargets to 0
    repeat with theProject in projects in workspaceDocument
        set totalTargets to totalTargets + (count of targets of theProject)
    end repeat

    -- For each target, wait a short amount of time
    repeat totalTargets times
        delay 3.0
    end repeat

    quit

end tell

You’ll need to change the workspace path, the workspace name and the scheme name for your case.

There are many ways of running AppleScript from the command line, including the osascript command, but I’ve been doing it from Python.

like image 132
Gary Makin Avatar answered Sep 07 '25 17:09

Gary Makin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!