How to keep an application activated/in foreground while a script is running?
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?
Now, if only Xcode 4 was at least as scriptable as Xcode 3, I wouldn’t have to resort to GUI automation.
- “Sort Lines in Selection” for Xcode 4
- Does anybody know what the xcode file “InfoPlist.strings (English)” is?
- Tell AppleScript To Build XCode Project
- Is there a way to list all files and their targets in Xcode?
- Where is the Run Script and Build Phase in Xcode 8?
- Can the UI Automation instrument be run from the command line?
3 Solutions Collect From Internet About “How to keep an application activated/in foreground while a script is running?”
You can just use the
activate command for every
click call to ensure that the application is in the foreground. It’s not ideal. Really if you’re going to use System Events for scripting input like this you have to just accept that the user can’t really use the computer whilst the script is running!
If you can break the script down into parts that require user input and parts that don’t, you could present a dialog to the user saying something like, “Are you ready to continue with the script? You’ll have to leave your computer for a while!”
… and then when it’s finished, “Feel free to use your computer again now!”
This might make the script a little less obtrusive. Just a suggestion.
you should put up some of loading image or something while it is running also anytime you call a gui you should run a loop with a timeout that activates the app then checks for the existence of the items you want to click then when it exists click it and get out of the loop
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”.
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
- tableview image content selection color
- Why NSNumber points to the same address when value are equals?
- Send multiple OBD commands together and get response simultaneously
- Dealing with different size images in a xib for iPhone5 versus iPhone4?
- How to write a file to a folder located at Apple's Files App in Swift 4?
- ViewWillDisappear not getting called searchcontroller
- Add UISearchBar to UINavigationBar with UIBarButtonItem
- How to migrate Alamofire router class to Swift 3?
- Adding an Xcode subproject: Shouldn't all the source files get copied?
- handleWatchKitExtensionRequest not responding to openParentApplication in Watchkit Extension (Swift)
- Why does my time UILabels skip 2 seconds when it resumes play from a pause state?
- Exchange Date between UITableViewController and ContentViewController with multiple pages
- iCalendar .ics accept/decline on iOS
- How to make image spin (animation)
- Failed to install app error: Invalid Bundle – No Apple Watch Binary