Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:54:35+00:00 2026-06-03T14:54:35+00:00

I have a simple script for programmatically launching an iOS project through XCode: on

  • 0

I have a simple script for programmatically launching an iOS project through XCode:

on run project_loc
  tell application "Xcode"
    open project_loc
    activate
  end tell

  tell application "System Events"
    tell application process "Xcode"
      click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
    end tell
  end tell
end run 

This works well, except that it switches focus to Xcode, which isn’t ideal because I’m trying to use this as part of a scheme that automatically recompiles and relaunches in response to any change in relevant files. Is there any way to accomplish this without giving focus to the Xcode window?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:54:36+00:00Added an answer on June 3, 2026 at 2:54 pm

    You cannot use GUI Scripting to click a menu item without switching to the application any more than you can click it yourself without doing so – the menu bar of an application is only available when it has focus (or, at least, was the last app to have focus – it doesn’t necessarily need a focused window). However, you can alleviate the disruptiveness of the switch by switching back to your previously focused app inside your script:

    on run
        tell application "System Events" to set focusedAppID to bundle identifier of first application process whose frontmost is true
        <your code here>
        tell application id focusedAppID to activate
    end run
    

    But … Xcode itself is a scriptable application. If all you need is for the project to build, why not use

    tell application "Xcode" to build <target / project>
    

    which will spare you the can of worms GUI Scripting is – have a look at the Xcode AppleScript dictionary (not added by default – just drag Xcode.app to the library window in AppleScript editor).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple script: #!/bin/sh column=$1 awk '{print $'$column'}' When I run: ls -la
i have this simple script of a popunder window: function loadpopunder(){ win2=window.open(popunder,,winfeatures) win2.blur() window.focus()
I have a simple script I'm trying to run: <?php print exec('whoami'); $output2 =
I have simple script, I want to get my images and then divide them
i have this simple script: function paginateUsers(page){ get( _config_remote_host+'/users?page='+page,function(json){ json = JSON.parse(json); var _html
I have a simple script that pulls about 30,000 characters of JSON. I get
I have a simple script that does some search and replace. This is basically
I have a simple script that pulls about 100 million results, 1 million at
OK I have a simple script at http://kleague.org/test/ Type a movie name and it
I have simple table creating script in Postgres 9.1. I need it to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.