如何在脚本运行时保证应用程序的激活/在前台? [英] How to keep an application activated/in foreground while a script is running?
问题描述
我使用AppleScript来自动根据X code 4应用程序的部署。
我使用的系统事件,单击该菜单栏的菜单项。我有整个事情的工作,但是有一个怪癖。如果用户点击其他地方我的脚本运行时,即在X code 4窗口熄灭前景,我的整个脚本失败。有没有办法强制X code语言中可以从我的脚本前景?
I'm using Applescript to automate deployment of applications from Xcode 4. I use System Events to click the menu items in the menu bar for that. I have the whole thing working, but with one quirk. If the user clicks elsewhere while my script is running, that is the XCode 4 window goes out of foreground, my entire script fails. Is there a way to force Xcode to be in the foreground from my script?
现在,如果只适用于X code 4至少是为X code 3为脚本的,我也不会求助于GUI自动化。
Now, if only Xcode 4 was at least as scriptable as Xcode 3, I wouldn't have to resort to GUI automation.
推荐答案
mcgrailm和詹姆斯·贝德福德的回答的组合工作。
我把菜单点击编辑方案......在一个循环,直到编辑计划表就存在。
我也有激活应用程序之前,我点击运行无建设。
A combination of mcgrailm and James Bedford's answers worked. I put the menu click for "Edit Schemes…" in a loop until the edit scheme sheet becomes existent. I also had to activate the application just before I clicked "Run without building".
在code:
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
这篇关于如何在脚本运行时保证应用程序的激活/在前台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!