0

I have a terminal shortcut on my dock which I use every day. Depending on my monitor setup (extra, 2 extra, etc.) to my Macbook Pro, I like to have a different launching scheme (either 4 windows or 5 windows).

Is there a way to have 2 (or more) terminal launchers on the dock, one which launches the "4 windows" setup and one which launches the "5 windows" setup?

  • Is Terminal going to be running when you click on these? – 0942v8653 Feb 19 '15 at 13:41
  • preferably not. Imagine I quit out of everything and want to start it up from scratch. For example, the one I have now launches 4 windows (if it is not running), but will only launch one window if terminal is currently running. I would like that same functionality, but just two different shortcuts - one for each window group. – drjrm3 Feb 19 '15 at 13:51
  • How is the original Launcher constructed – markhunte Feb 19 '15 at 15:14
  • Not sure what you mean - I just dragged the App icon onto my taskbar! – drjrm3 Feb 19 '15 at 15:56
  • Sorry I misread your comment. I have just constructed an applescript and will post an answer in a second. – markhunte Feb 19 '15 at 16:14
0

Here's how you can switch Terminal's startup window group automatically:

defaults write com.apple.Terminal 'Startup Window Group' 'four-windows'
defaults write com.apple.Terminal 'Startup Window Group' 'five-windows'

(four-windows and five-windows should be replaced with the Terminal window group names.)

You can use AppleScript or Automator to make an app that does that then launches Terminal:

-- AppleScript version
do shell script "defaults write com.apple.Terminal 'Startup Window Group' 'four-windows'"
tell app "Terminal" to activate

Or you can use my linkapp script to make a new app bundle that will do the same thing, and the icon will stay there.

python linkapp.py /Applications/Utilities/Terminal.app ./term-layout-4.app

Then when it gives you the wrapper script, edit it and add the defaults write line above the "$executable".

#!/usr/bin/env bash
executable="$(dirname "$0")/Terminal"

defaults write com.apple.Terminal 'Startup Window Group' 'four-windows'

"$executable" 

You can then do the same with your other window group. One caveat with linkapp.py is that you can't run them both at the same time, because it will try to restore your windows.

If you want you can change the icon too (but if you don't use linkapp.py, the normal Terminal icon will be what shows up in your Dock and Command+Tab when it's running).

  • quick question - how do I tell it to just launch the basic, original window? Do I need to make a new "one-window" group that just launches the original window? – drjrm3 Mar 6 '15 at 13:59
  • I think you could turn off starting with a window group but it would probably be easier just to use another group – 0942v8653 Mar 6 '15 at 15:12
0

You can save the below Applescript as a Application.

Do not set stay open when saving.

This script when saved as an App. Will allow you to configure as many windows as you need and open them in the same positions.

You can save the Script any number of times as new App. and configure each App to control different sets of Terminal windows.


When you run the script it will:

  • Detect if any Terminal window bounds have been saved to it's windowBounds property

If it does not find any it will prompt you to set some up.

  • Hit yes to save you current Terminal windows.

You will of course need some windows open , so if you do not have them open yet:

  • hit no , set up your terminal windows and run the App again.

The App will always quit after it has run.

  • Now when you run the App again it will open as many windows as you had set up and in the same places.

A second feature is you can change the window set up.

If you hold down the shift key while clicking on the App icon to launch it.

The App will give you the option to save the current Terminal windows as its windowBounds config. This does overwrite the previous ones.


To have more than one config. I could expand the app to do this. But it is simpler to just create two of the Apps and name them differently. Place them in your dock. ta da...

The script.


    property windowBounds : {}


if windowBounds is {} then


    display()

else
    nowRun()

end if

on display()
    display dialog "Set the current Terminal windows to app. now?" buttons {"Yes", "No"} default button 2
    if the button returned of the result is "Yes" then
        setBounds()

    end if

end display

on nowRun()

    if not isShiftKeyPressed() then
        tell application "Terminal"
            activate
            close windows
            delay 1
            repeat with i from 1 to number of items in windowBounds
                set this_item to item i of windowBounds
                do script "proHelp"
                set bounds of window 1 to this_item
            end repeat
        end tell

    else

        display()

    end if
end nowRun
on setBounds()
    tell application "Terminal"
        set windowBounds to bounds of windows

    end tell


end setBounds

on isShiftKeyPressed()

    return (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa. NSShiftKeyMask > 1'") is "True"
end isShiftKeyPressed

Update 2.

Moved close windows

In the nowRun() handle.

This allows the app to be used if Terminal is Running or not. It will now close any windows currently open and bring up the configured ones.

Which is handy when you first launch Terminal and get a default window opening.

You must log in to answer this question.

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