2011-09-02 4 views
10

이 주제에 대해 이미 질문이 있지만 (특히 다음 중 하나 : Tell AppleScript To Build XCode Project) 찾을 수있는 것들을 읽었을 때 감사합니다. Xcode의 현재 버전에는 해답이없는 것 같습니다.Xcode 4.1을 자동화하여 정리, 빌드 및 실행하는 AppleScript 구문

질문과 마찬가지로, Xcode 프로젝트를 열고, 빌드 한 다음 iPhone Simulator (v4.3)에서 앱을 실행하려고합니다. 나는이 프로그램을 실행할 때, 불행하게도

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 

: 다른 질문의 답변에 따라

, 내가 쓴 다음 스크립트 : 문제의 프로젝트는 셀레늄 프로젝트의 iPhoneDriver이 (http://code.google.com/p/selenium/wiki/IPhoneDriver 자세한 내용은 여기를 참조) 다음을 얻습니다 :

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 

오픈 명령을 실행하면 Xcode는 프로젝트를 아무런 문제없이 엽니 다. 그러나 스크립트의 나머지 부분을 포함하자마자 도크의 Xcode 아이콘이 튀어 나오지 만, 위의 내용은 별개로 AppleScript 편집기에서 가져옵니다.

아무도 내가 뭘 잘못하고 있다고 조언 할 수 있습니까? AppleScript 나 Xcode를 처음 사용하기 때문에 문제를 진단하는 데 어려움을 겪고 있습니다.

Xcode AppleScript 사전을 살펴 보았습니다. 그러나 작업 예제가 없으면 필요한 구문을 결정할 수 없습니다.

미리 도움을 청하십시오! 당신은 엑스 코드는 포 그라운드로 오는 확인을 경우

+0

나는 혼란 스럽다. 프로젝트를 "빌드"또는 "실행"하시겠습니까? –

답변

3

, 내가 대신을 사용합니다 :

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 
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 

이 기능이 작동하는지 알려주세요. iPhone 프로젝트와 함께 Xcode 4.2.1을 Lion에서 테스트했습니다.

+0

놀라운 :-). 나는 이것이 더 upvoted되지 않은 것을 믿을 수 없다. –

+0

이 스크립트를 실행하는 방법은 무엇입니까? 쉘 스크립트 1 개와 애플 스크립트 1 개를 만들고 쉘 스크립트에서 사과 스크립트를 호출해야합니까? Xcode 4.2.1을 어떻게 테스트 했습니까? – Abhinav

+0

@Abhinav AppleScript 편집기 (/ 응용 프로그램/유틸리티에 설치됨)에 스크립트를 복사하여 붙여 넣기 만하면됩니다. "Xcode 4.2.1을 어떻게 테스트 했습니까?" => 무슨 뜻이야? – Guillaume

0

위의 AppleScript는 정말 훌륭하고 (또한 작동합니다 ...) 전문가이며, 구버전과 극단적 인 경우 등을 돌보는 사람들입니다. 질문에 의해 제안 된 스크립트는 처음 장소.

작동하지 않는 이유는 Xcode 스크립팅 기능이 깨졌습니다. "깨끗한"뿐만 아니라 작동하지 않습니다. Xcode의 내부 개체 모델로 수행하려고 시도한 대부분의 작업이 작동하지 않습니다.

AppleScript 아키텍처 (OSA)는 AppleScripts가 참조 할 수있는 "인간이 이해할 수있는"개체 그래프를 노출하는 응용 프로그램이 필요합니다. 애플리케이션 스크립팅이 약할 때

tell target "my library" of project "my project" of workspace "my workspace" to clean. 

또는

tell application "Xcode" to close all projects whose name contains "Lib" 

사용자 인터페이스 스크립팅 스크립터의 최후의 수단은 다음과 같이 엑스 코드에서이 보일 수 있습니다. UI 계층 구조는 본질적으로 표준이며 스크립팅 기능은 Cocoa에서 무료이므로 항상 작동합니다.