2

I found the same question and a strong answer on SO: https://stackoverflow.com/q/4404242/147265

I'm looking to launch new terminals from the CLI in a different profile than my default. My current implementation opens a new terminal no problem, but I don't know the option to set the profile.

open_term () {                                                 
  osascript -e "tell app \"Terminal\"
     do script \"clear; hello $1 \"
  end tell"
}
open_term world

The new terminal will open and greet with "hello world"

I would expect there to be some option for Terminal to specify profile, like -p "Man Page".

Here is the closest I've found to docs, but no profile option or similar: Terminal.app readme

3 Answers 3

3

You can export your settings profile from the preferences window, then open the settings file with the open command. For example:

bash-3.2$ open "Documents/Man Page.terminal"
5
  • 1
    Wow! That's fantastic! Is there a way to pass a command while opening?
    – Adam
    Mar 19, 2014 at 22:21
  • I found that I can dig into the props with this question: stackoverflow.com/questions/1150380/… I'm now looking at how to pass a parameter.
    – Adam
    Mar 19, 2014 at 22:29
  • Just add the parameter to the start command.
    – audiomason
    Mar 19, 2014 at 22:36
  • Yeah, I can do a hard coded one, but I'm looking to pass parameters. This question looks to be right in line with what I'm looking for: stackoverflow.com/questions/4404242/…
    – Adam
    Mar 19, 2014 at 22:41
  • 2
    Each time I open Documents/CLI.terminal, Terminal creates a new entry in the Terminal profiles list (Terminal settings). When I first run it, I see a new CLI 1 profile show up. Run again and CLI 2 profile shows up, then CLI 3 and so on. How do I prevent this build up?
    – djb
    Oct 28, 2021 at 15:53
1

To run a particular command in the terminal such as a script called yourcommand stored in your bin directory, use 'export settings' from a terminal profile that you like to create a file with extension .terminal, then edit the .terminal file in a text editor and specify

    <key>CommandString</key>
    <string>/Users/youruserid/bin/yourcommand</string>  
    <key>RunCommandAsShell</key>
    <true/>

Then you can double-click or use the open command to run this and open a new terminal on this command.

0

@djb: I found the way to prevent opening .terminal files from creating duplicate profiles is to edit the files and remove the <name> key, if it is present. i.e.:

<key>name</key>
<string>vpn.MacMini2.wan.green</string>
2
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 5, 2022 at 9:35
  • This didn't work for me on macOS Ventura Mar 8 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .