AppleScript调用Xcode编译启动报错:预期换行等但找到类名
Troubleshooting AppleScript Error When Calling Xcode
Let's break down what's causing your script error and fix it step by step.
The Root Cause
Your script is throwing the end of line, etc. expected (s) but class name found error because you're not using the correct syntax for Xcode's AppleScript commands. Xcode's scripting interface requires explicit parameter labels when calling commands like build or run—you can't just pass the project/target object directly.
Issues in Your Original Script
- Incorrect
buildcommand:build targetProjectis invalid syntax. Xcode needs you to specify that you're targeting a project/target with thetargetparameter label. - Non-existent
launchcommand: Xcode doesn't have alaunchcommand for projects/targets. To run your built target, you should use theruncommand instead.
Fixed Script
Here's the corrected version of your script with proper syntax:
tell application "Xcode" activate -- Check if there's an active project document first to avoid errors if exists active project document then set targetProject to project of active project document -- Build the target with proper parameter labeling if (build target targetProject) is equal to "Build succeeded" then -- Run the target using the correct command run target targetProject end if else display dialog "No active Xcode project document found!" end if end tell
Additional Notes
- I added a check for an
active project documentto prevent the script from failing if no project is open in Xcode. - Xcode's
buildcommand returns a string like "Build succeeded" or "Build failed", so your original condition is valid once the command syntax is fixed.
内容的提问来源于stack exchange,提问作者Athmane
相关产品推荐
相关产品推荐

