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.
- Run AppleScript from Cocoa Application
- Can the UI Automation instrument be run from the command line?
- Sandbox entitlement to script iTunes via NSAppleScript
- Does anybody know what the xcode file “InfoPlist.strings (English)” is?
- Quit app after window is closed in AppleScript
- How to refresh finder window?
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
- ios swift: How to have one static cell in a dynamic tableview?
- Best practice to send a lot of data in background on iOS4 device?
- Emoji to JSON encoded, post to web server
- Draw a circle of 1000m radius around users location in MKMapView
- changing property contentsGravity in transform-only layer, will have no effect
- How to bind an Objective-C static library to Xamarin.iOS?
- Selecting the text just updated with replaceRange(range: UITextRange, withText: String)
- iOS Swift MapKit Custom Annotation
- How to take NSString after specific character which occurs multiple time in NSString?
- Images can't contain alpha channels or transparencies
- UISearchBar modifying its frame/bounds when clicked
- Changing UILabel text but keeping the rest of the attributes
- How to activate action sheet buttons with swift?
- How to add a UIToolbar to a UITableViewController programmatically?
- UITableViewCell ImageView not scaling properly?