Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I've got multiple terminal tabs open, and I want to be able to close the current tab. How can I make the current terminal tab be the active tab, so that I can close that tab with +w?

I am in the default Mac terminal.

share|improve this question

migrated from unix.stackexchange.com Jul 18 '13 at 2:25

This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems..

2 Answers 2

In OSX Terminal, hold down the keys +Shift while arrowing right or left. This will allow you to switch between active tabs.

When on the tab you wish to close, as you noted, +w will close that tab.

share|improve this answer

If you're trying to do it in a script, you might use something like this:

tell application "Terminal"
    repeat with w in (get windows)
        repeat with t in (get tabs of w)
            if processes of t contains "man" then
                set selected of t to true
                set index of w to 1
            end if
            --properties of t
        end repeat
    end repeat
end tell
tell application "System Events" to tell process "Terminal"
    perform action "AXRaise" of window 1
    tell menu 3 of menu bar 1
        if enabled of menu item "Close Tab" then
            click menu item "Close Tab"
        else
            click menu item "Close Window"
        end if
    end tell
end tell

Tab objects don't have a close command. set index to 1 doesn't actually raise a window, but it makes it it appear as window 1 to System Events, which supports the AXRaise action.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.