我使用AppleScript从Xcode的4 自动部署应用程序我用系统事件,请点击相应的菜单栏的菜单项。我有整个事情的工作,但有一个怪癖。如果用户在脚本运行时点击其他地方,那就是XCode 4窗口不在前台,我的整个脚本都会失败。有没有办法强制Xcode在我的脚本前台?如何在脚本运行时将应用程序激活/保存在前台?
现在,只要Xcode的4至少可编写脚本的Xcode中3,我就不必求助于GUI自动化。
我使用AppleScript从Xcode的4 自动部署应用程序我用系统事件,请点击相应的菜单栏的菜单项。我有整个事情的工作,但有一个怪癖。如果用户在脚本运行时点击其他地方,那就是XCode 4窗口不在前台,我的整个脚本都会失败。有没有办法强制Xcode在我的脚本前台?如何在脚本运行时将应用程序激活/保存在前台?
现在,只要Xcode的4至少可编写脚本的Xcode中3,我就不必求助于GUI自动化。
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
您可以对每个click
调用使用activate
命令以确保应用程序处于前台。这并不理想。真的,如果你打算使用系统事件来进行脚本输入,你必须接受用户在脚本运行时不能真正使用计算机!
如果你能分解剧本到需要用户输入和零件部件不,你可以显示一个对话框向用户说了一句“你准备好继续脚本?你必须离开你的电脑一段时间!“ ......然后当它结束时,“随时可以再次使用您的电脑!” 这可能会使脚本稍微不显眼。只是一个建议。
检查是否存在然后激活是个好主意。如果异常处理和恢复执行,我可以做些什么? – Plumenator 2011-03-29 18:20:05
其实我尝试这样做。我认为它只需点击几下,而不是其他的。我会再试一次。 – Plumenator 2011-03-29 18:18:33
您可能必须在激活和点击之间放置一些小的延迟,因为AppleScript可能会超越自己。使用这种脚本方法时这很常见。 – 2011-03-29 19:17:49