0

I'm using OSX Yosemite and the built-in terminal on my Mac. I have quite a few terminal windows running most of the time and it's hard to navigate around in all of them as they all look alike. So what I want to do is run my commands as usual, but in a new terminal window with a chosen profile.

Normally to open my_script in vim I would type in command line

$ vim my_script

but I want to be able to write something like this:

$ vim my_script (as before) and then some command saying "open this in a new terminal window with profile = Homebrew"

Does anyone know if this is possible? Thank you very much.

1 Answers1

0

Enter AppleScript.

It doesn't achieve exactly what you describe but I think it's close enough. Whether or not you use this is up to you.

You can use this command

osascript -e 'tell app "system events" to tell process "Terminal" to tell menu bar 1 to tell menu bar item "Shell" to tell menu "Shell" to tell menu item "New Window" to tell menu "New Window" to click menu item "Basic"'

or, in expanded form

tell app "system events" 
    tell process "Terminal" 
        tell menu bar 1 
            tell menu bar item "Shell" 
                tell menu "Shell" 
                    tell menu item "New Window" 
                        tell menu "New Window" 
                            click menu item "Basic" #or any other profile
                        end tell
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

To create a new Terminal window with the desired profile. (In this example I used Basic)

If you get the error

System Events got an error: osascript is not allowed assistive access

then see this SO answer by @NGAFD on how to solve that.

Go to System Preferences > Security and Privacy > Privacy > Accessibility and make sure Terminal is in the list and checked.

Community
  • 1
  • 1
Arc676
  • 4,445
  • 3
  • 28
  • 44