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 3792112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:34:21+00:00 2026-05-19T12:34:21+00:00

I have two windows/tabs set up to run in Terminal.app, syd and mel. i.e.

  • 0

I have two windows/tabs set up to run in Terminal.app, “syd” and “mel”. i.e. in Shell | New Window, “syd” and “mel” are listed. How can I open these terminal configurations with AppleScript?

  • 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-19T12:34:21+00:00Added an answer on May 19, 2026 at 12:34 pm

    A few weeks ago, I migrated a new Snow Leopard (10.6) machine from a Tiger (10.4) machine. Tiger’s Terminal stored its settings in “.term“ files (usually in ~/Library/Application Support/Terminal/, but they could be saved/moved anywhere); Snow Leopard’s Terminal centralized its settings into its preference file.

    Prior to migrating to Snow Leopard a part of one of my normal workflows was using Finder to double click on a saved “.term” file to open a Terminal window with a preset size and initial command. Today, I noticed that each time I did this Terminal was creating a duplicate “settings set”. So, I started looking for a way to start a saved setting that did not involve opening a “.term” file (so that the duplicate settings would not pile up); AppleScript was my first stop since I have had a bit of experience with it before.

    In short, there seems to be no direct way to start a new window/tab with a particular “settings set” via Terminal’s AppleScript commands. The usual approach would be to do something involving make new window (or make new tab), but I could not find a variation that Terminal would accept. I came up with three alternate solutions (the last is the best, in my opinion).

    Create a Window, Then Change Settings

    If your settings do not involve an initial command or a different size from your default settings (e.g. only color/keyboard/behavioral settings are different from the default), you could use Terminal’s do script command (without a “text“ parameter) to create a new new window and then change its settings set to the one you wanted.

    tell application "Terminal"
        set newTab to do script -- create a new window with no initial command
        set current settings of newTab to settings set "Grass"
    end tell
    

    This might work for you, but it was not appropriate for my needs, so I continued my search.

    Terminal’s default settings

    Next, I looked to the default settings property. I thought it would be possible to temporarily change which setting is the default, create a new window, then reset the default setting. This approach was eventually successful, but it turned out to be quite ugly (besides the ugliness of the temporary change to the defaults).

    I used System Events’ keystroke command to send a ⌘N to Terminal to create the new window. It turns out that Terminal is sometimes a bit slow to create the new window and my script would end up reseting the default before Terminal had a chance to use the temporary value the earlier part of the script had arranged. do script would have been synchronous, but it would also nullify any initial command saved as a part of the settings. I ended up resorting to counting the number of windows before the ⌘N and waiting for the number of windows to increase. If the launched command results in a very quick opening and closing of a window, there is a chance that this loop could get stuck. I could limited the iterations, but by this point I was quite disappointed with the overall flavor of the code (though I did go ahead and extend it to allow for new tabs instead of just windows).

    to newTerminal(settingSetName, asTab)
        tell application "Terminal"
            if asTab is true then
                set countRef to a reference to tabs of first window
                set newKey to "t"
            else
                set countRef to a reference to windows
                set newKey to "n"
            end if
            set originalDefault to name of default settings
            set default settings to settings set settingSetName
        end tell
        try
            set initialCount to count of countRef
            tell application "System Events"
                -- keystrokes always go to the frontmost application
                set frontmost of application process "Terminal" to true
                keystroke newKey using command down
            end tell
            repeat until (count of countRef) > initialCount
                beep
                delay 0.1
            end repeat
    
            tell application "Terminal" to set default settings to settings set originalDefault
        on error m number n
            try
                tell application "Terminal" to set default settings to settings set originalDefault
            end try
            error m number n
        end try
    end newTerminal
    
    newTerminal("Grass", false)
    

    Click a Menu Item via System Events

    With System Events, there is a way to directly activate the menu items Shell > New Tab and Shell > New Window. This requires that “access for assistive devices” is enabled (near the bottom of the Universal Access preference pane; I usually have it enabled because the GUI scripting that can then be done via System Events is often the only (good) way to accomplish some automation tasks). Although the prior variation also uses System Events, its very limited use does not require “access for assistive devices”.

    (* makeNewTerminal(settingsSetName, asTab)
    
        Bring Terminal.app to the front and
            click the menu item named <settingsSetName>.
            If <asTab> is true, then use the menu item under Shell > New Tab,
                otherwise use the menu item under Shell > New Window
    *)
    to makeNewTerminal(settingsSetName, asTab)
        tell application "Terminal" to launch
        if asTab is true then
            set submenuName to "New Tab"
        else
            set submenuName to "New Window"
        end if
        tell application "System Events"
            set terminal to application process "Terminal"
            set frontmost of terminal to true
            click menu item settingsSetName of ¬
                first menu of menu item submenuName of ¬
                first menu of menu bar item "Shell" of ¬
                first menu bar of terminal
        end tell
    end makeNewTerminal
    
    makeNewTerminal("Grass", true)
    

    This approach literally automates the selection and activation of one of the menu items from the Shell menu. It does require “access for assistive devices”, but the code is much simpler and has fewer problematic areas (the major issue with this code is localization).

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

Sidebar

Related Questions

I have the following extJs window which has two tabs in it. One of
How can you combine two windows in Screen? I have two windows such that
I have two versions of a Windows Forms Application and can't figure for the
Assume you have two web applications running in two different tabs/windows in your browser.
I have an webapplication which is running in two different browser windows/tabs at the
I have two windows application, one is a windows service which create EventWaitHandle and
Let's say I have two windows services running. One service is 'Polling' - it
I want to have two Emacs windows on the screen: one for Dired and
I have two installations of Windows 7. a 64bit version on my hard disk,
Two Windows processes have memory mapped the same shared file. If the file consists

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.