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

  • SEARCH
  • Home
  • 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 7606869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:31:03+00:00 2026-05-31T00:31:03+00:00

If no Terminal app is open, the following code opens TWO Terminal windows. Why

  • 0

If no Terminal app is open, the following code opens TWO Terminal windows. Why is it doing this? I only want one window to open.

If only one Terminal window is open, then the following code opens only ONE additional window.

NSAppleScript* terminal = [[NSAppleScript alloc] initWithSource:
                           [NSString stringWithFormat:
                                @"tell application \"Terminal\"\n"
                                @"    activate\n"
                                @"    do script \"echo %@\"\n"
                                @"    tell the front window\n"
                                @"    set title displays shell path to false\n"
                                @"    set title displays custom title to true\n"
                                @"    set custom title to \"My session! %@\"\n"
                                @"    end tell\n"
                                @"end tell", name, name]];

[terminal executeAndReturnError:nil];
  • 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-05-31T00:31:04+00:00Added an answer on May 31, 2026 at 12:31 am

    The do script command, as you’ve written it, will always run in a new window. If you’d like it to run in a specific window, use the following format: do script (...) in (window...). Terminal’s in syntax can also handle running scripts in tabs.

    For instance, if you’d like to run a script in the frontmost window, you can write do script "echo Hello, world!" in front window.


    Edit: To follow up, if you’d like to always run the script in a window (create a new one if none are open), you can use the following AppleScript:

    tell application "Terminal"
        activate
        if length of (get every window) is 0 then
            tell application "System Events" to tell process "Terminal" to click menu item "New Window" of menu "File" of menu bar 1
        end if
        do script "echo Hello, world!" in front window
    end tell
    

    Of course, you’ll need to correctly escape it in an NSArray, but that I’m sure you can do.

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

Sidebar

Related Questions

If I have several OS-X Terminal.app windows open, how can I move one Terminal
I have two windows/tabs set up to run in Terminal.app, syd and mel. i.e.
On my Mac, there is no window open when I start Terminal app. I
I've used poderosa(a .NET terminal app) to monitor logs on multiple linux/solaris servers. This
On a Terminal Server install of my .NET 2.0 WinForms app, one of my
How can I open a symlink without the terminal window popping up? Moreover, when
I set an alias in my .bash_profile for Octave alias octave=open /Applications/Octave.app It opens
I just created an app on Facebook (Open Graph). I want to publish a
I really like being able to the command-line tool gitx from Terminal.app to open
I really like being able to the command-line tool gitx from Terminal.app to open

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.