AppleScript语法自动化Xcode 4.1以清理,构建然后运行

Ben*_*enA 10 xcode selenium applescript automation xcode4

我很欣赏已经有关于这个主题的问题,但是阅读了我能找到的内容(特别是这一篇:告诉AppleScript构建XCode项目),它们似乎都已经有几年了,答案似乎并不适用到当前版本的Xcode.

与链接的问题类似,我试图自动打开Xcode项目,构建它然后在iPhone模拟器(v4.3)中运行应用程序.有问题的项目是Selenium项目的iPhoneDriver(详见此处:http://code.google.com/p/selenium/wiki/IPhoneDriver)

基于另一个问题的答案,我编写了以下脚本:

tell application "Xcode"
    open "/Users/<username>/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
    tell project "iWebDriver"
         clean
         build
         try
             debug
         end try
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我运行这个时,我得到以下内容:

tell application "Xcode"
open "/Users/ben.adderson/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
    --> project document "iWebDriver.xcodeproj"
clean project "iWebDriver"
    --> missing value
build project "iWebDriver"
    --> missing value
debug project "iWebDriver"
    --> error number -1708
end tell
Run Code Online (Sandbox Code Playgroud)

如果我只运行open命令,Xcode会毫无问题地打开项目.但是,只要我包含脚本的其余部分,Dock中的Xcode图标就会反弹,但除了上面的AppleScript编辑器之外,这就是我所得到的.

谁能告诉我我做错了什么?这是我第一次使用AppleScript或Xcode,所以我很难诊断问题.

我已经尝试过查看Xcode AppleScript字典,但没有实际的例子,我无法确定我需要的语法.

在此先感谢您的帮助!

Gui*_*ume 12

使用AppleScript和命令行工具(xcodebuild)的混合,我提出了这个:

-- This script will clean, build then run the project at the path below.
-- You will need to slightly modify this script if you have more than one xcodeproject at this path

set pathOfXcodeProject to "/Users/<username>/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
-- End of configuration



do shell script "cd " & pathOfXcodeProject & " && /usr/bin/xcodebuild clean build "

tell application "Xcode"

    open pathOfXcodeProject
    activate
end tell

tell application "System Events"
    get system attribute "sysv"
    if result is greater than or equal to 4144 then -- Mac OS X 10.3.0
        if UI elements enabled then
            tell application process "Xcode"
                click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1

            end tell
        else
            beep
            display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
            if button returned of result is "OK" then
                tell application "System Preferences"
                    activate
                    set current pane to pane "com.apple.preference.universalaccess"
                end tell
            end if
        end if
    else
        beep
        display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
    end if
end tell
Run Code Online (Sandbox Code Playgroud)

如果这对您有用,请告诉我.我在Lion上使用iPhone项目对Xcode 4.2.1进行了测试.


psi*_*kjr 3

如果你同意 Xcode 进入前台,我会使用这个:

tell application "Xcode"
    activate
    open "/Users/<username>/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
end tell

tell application "System Events"
    key code 15 using {command down}
end tell
Run Code Online (Sandbox Code Playgroud)