2011-03-29 30 views
0

我使用AppleScript從Xcode的4 自動部署應用程序我用系統事件,請點擊相應的菜單欄的菜單項。我有整個事情的工作,但有一個怪癖。如果用戶在腳本運行時點擊其他地方,那就是XCode 4窗口不在前臺,我的整個腳本都會失敗。有沒有辦法強制Xcode在我的腳本前臺?如何在腳本運行時將應用程序激活/保存在前臺?

現在,只要Xcode的4至少可編寫腳本的Xcode中3,我就不必求助於GUI自動化。

回答

0

mcgrailm的組合和詹姆斯·貝德福德的答覆工作。 我在菜單中點擊「編輯方案...」,直到編輯方案表變得存在。 我還必須在點擊「Run without building」之前激活應用程序。

代碼:

tell application id "com.apple.dt.Xcode" 
    activate 
end tell 
tell application "System Events" 
    tell process "Xcode" 
      repeat until sheet 1 of window 2 exists 
        click menu item "Edit Scheme…" of menu "Product" of menu bar item "Product" of menu bar 1 
        tell application "Xcode" 
          activate 
          beep 
        end tell 
      end repeat 
      tell sheet 1 of window 2 
        set destination to pop up button 2 of group 1 
        click destination 
        set target to "iPad 4.3 Simulator" 
        click menu item target of destination's menu 1 
        set buildConfig to pop up button 3 of group 2 
        click buildConfig 
        click menu item "Debug" of menu 1 of buildConfig 
        click button "OK" 
      end tell 
      tell application "Xcode" 
        activate 
        beep 
      end tell 
      tell application id "com.apple.dt.Xcode" 
        activate 
      end tell 
      click menu item "Run Without Building" of menu 1 of menu item "Perform Action" of menu "Product" of menu bar item "Product" of menu bar 1 
    end tell 
end tell 
1

您可以對每個click調用使用activate命令以確保應用程序處於前臺。這並不理想。真的,如果你打算使用系統事件來進行腳本輸入,你必須接受用戶在腳本運行時不能真正使用計算機!

如果你能分解劇本到需要用戶輸入和零件部件不,你可以顯示一個對話框向用戶說了一句「你準備好繼續腳本?你必須離開你的電腦一段時間!「 ......然後當它結束時,「隨時可以再次使用您的電腦!」 這可能會使腳本稍微不顯眼。只是一個建議。

+0

其實我嘗試這樣做。我認爲它只需點擊幾下,而不是其他的。我會再試一次。 – Plumenator 2011-03-29 18:18:33

+0

您可能必須在激活和點擊之間放置一些小的延遲,因爲AppleScript可能會超越自己。使用這種腳本方法時這很常見。 – 2011-03-29 19:17:49

1

你應該把一些加載圖片什麼的,同時它也運行任何時候你調用一個GUI您應該運行與激活的應用程序,然後檢查你要點擊那麼當項目存在超時循環它存在單擊它,走出循環

編輯

helpful link

+0

檢查是否存在然後激活是個好主意。如果異常處理和恢復執行,我可以做些什麼? – Plumenator 2011-03-29 18:20:05

相關問題