For Xcode 16.4 use this AppleScript:
tell application "Xcode" activate set targetProject to active workspace document build targetProject run targetProject end tell