XcodeをEmacsから操作する

こちらのサイトEmacsからXcodeを操作して、コンパイルと実行を行う方法が紹介されています。
しかし、キーボード操作をエミュレーションする方法であるからか、たまに失敗することがあるようです。
こちらのサイトXcodeコンパイルと実行を自動化するスクリプトが紹介されているので、
これを元に、EmacsからXcodeを操作するためのelispスクリプトを作成したいと思います。

基本的に参照元シェルスクリプトelispに移植すればよいのですが、

build targetProject

の結果が、日本語環境では"Build succeeded"にならないため失敗してしまいます。
"Build succeeded"の代わりに"ビルドは問題なく完了しました"とすればよいようなのですが、
Xcodeを英語環境で起動することでも解決することができます。
Snow Leopardでアプリケーションごとに言語を変更する場合、Language Switcherというアプリケーションを用いればよいようです。

最終的に、次のようなelispスクリプトを作成しました。

(defun string-join (sep list-of-str)
  (mapconcat 'identity list-of-str sep))
(defun join-with-newline (&rest lines)
  (string-join "\n" lines))

(defvar iphone-simulator-version "3.1.3")
(defvar iphone-simulator-sdk
  (format "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator%s.sdk"
	  iphone-simulator-version))
(defvar iphone-simulator-sdk-string
  (format "iphonesimulator%s" iphone-simulator-version))

(defun xcode-build-and-launch-iphone-project ()
  (interactive)
  (let* ((abs-dir-name (file-name-directory (expand-file-name (buffer-file-name))))
	 (dir-name (file-name-nondirectory (directory-file-name abs-dir-name)))
	 (default-project-name (concat abs-dir-name dir-name ".xcodeproj"))
	 (project-name (read-file-name
			"project : "         ; prompt
			default-project-name ; directory
			nil		     ; default
			t		     ; existing
			)
		       )
	 )
    (do-applescript
     (format
      (join-with-newline
       "application \"iPhone Simulator\" quit"
       "application \"iPhone Simulator\" activate"
       "tell application \"Xcode\""
       "  open \"%s\""
       "  set targetProject to project of active project document"
       "  tell targetProject"
       "    set active build configuration type to build configuration type \"Debug\""
       "    set active SDK to \"%s\""
       "    set value of build setting \"SDKROOT\" of build configuration \"Debug\" of active target to \"%s\""
       "    if (build targetProject) is equal to \"Build succeeded\" then"
       "      launch targetProject"
       "    else"
       "      application \"iPhone Simulator\" quit"
       "    end if"
       "  end tell"
       "end tell"
       ) project-name iphone-simulator-sdk-string iphone-simulator-sdk))
    ))